diff --git a/assets/css/jquery.toast.css b/assets/css/jquery.toast.css new file mode 100644 index 0000000..54ddf67 --- /dev/null +++ b/assets/css/jquery.toast.css @@ -0,0 +1,28 @@ +/** + * jQuery toast plugin created by Kamran Ahmed copyright MIT license 2014 + */ +.jq-toast-wrap { display: block; position: fixed; width: 250px; pointer-events: none !important; margin: 0; padding: 0; letter-spacing: normal; z-index: 9000 !important; } +.jq-toast-wrap * { margin: 0; padding: 0; } + +.jq-toast-wrap.bottom-left { bottom: 20px; left: 20px; } +.jq-toast-wrap.bottom-right { bottom: 20px; right: 40px; } +.jq-toast-wrap.top-left { top: 20px; left: 20px; } +.jq-toast-wrap.top-right { top: 20px; right: 40px; } + +.jq-toast-single { display: block; width: 100%; padding: 10px; margin: 0px 0px 5px; border-radius: 4px; font-size: 12px; font-family: arial, sans-serif; line-height: 17px; position: relative; pointer-events: all !important; background-color: #444444; color: white; } + +.jq-toast-single h2 { font-family: arial, sans-serif; font-size: 14px; margin: 0px 0px 7px; background: none; color: inherit; line-height: inherit; letter-spacing: normal; } +.jq-toast-single a { color: #eee; text-decoration: none; font-weight: bold; border-bottom: 1px solid white; padding-bottom: 3px; font-size: 12px; } + +.jq-toast-single ul { margin: 0px 0px 0px 15px; background: none; padding:0px; } +.jq-toast-single ul li { list-style-type: disc !important; line-height: 17px; background: none; margin: 0; padding: 0; letter-spacing: normal; } + +.close-jq-toast-single { position: absolute; top: 3px; right: 7px; font-size: 14px; cursor: pointer; } + +.jq-toast-loader { display: block; position: absolute; top: -2px; height: 5px; width: 0%; left: 0; border-radius: 5px; background: red; } +.jq-toast-loaded { width: 100%; } +.jq-has-icon { padding: 10px 10px 10px 50px; background-repeat: no-repeat; background-position: 10px; } +.jq-icon-info { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGwSURBVEhLtZa9SgNBEMc9sUxxRcoUKSzSWIhXpFMhhYWFhaBg4yPYiWCXZxBLERsLRS3EQkEfwCKdjWJAwSKCgoKCcudv4O5YLrt7EzgXhiU3/4+b2ckmwVjJSpKkQ6wAi4gwhT+z3wRBcEz0yjSseUTrcRyfsHsXmD0AmbHOC9Ii8VImnuXBPglHpQ5wwSVM7sNnTG7Za4JwDdCjxyAiH3nyA2mtaTJufiDZ5dCaqlItILh1NHatfN5skvjx9Z38m69CgzuXmZgVrPIGE763Jx9qKsRozWYw6xOHdER+nn2KkO+Bb+UV5CBN6WC6QtBgbRVozrahAbmm6HtUsgtPC19tFdxXZYBOfkbmFJ1VaHA1VAHjd0pp70oTZzvR+EVrx2Ygfdsq6eu55BHYR8hlcki+n+kERUFG8BrA0BwjeAv2M8WLQBtcy+SD6fNsmnB3AlBLrgTtVW1c2QN4bVWLATaIS60J2Du5y1TiJgjSBvFVZgTmwCU+dAZFoPxGEEs8nyHC9Bwe2GvEJv2WXZb0vjdyFT4Cxk3e/kIqlOGoVLwwPevpYHT+00T+hWwXDf4AJAOUqWcDhbwAAAAASUVORK5CYII='); background-color: #31708f; color: #d9edf7; border-color: #bce8f1; } +.jq-icon-warning { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGYSURBVEhL5ZSvTsNQFMbXZGICMYGYmJhAQIJAICYQPAACiSDB8AiICQQJT4CqQEwgJvYASAQCiZiYmJhAIBATCARJy+9rTsldd8sKu1M0+dLb057v6/lbq/2rK0mS/TRNj9cWNAKPYIJII7gIxCcQ51cvqID+GIEX8ASG4B1bK5gIZFeQfoJdEXOfgX4QAQg7kH2A65yQ87lyxb27sggkAzAuFhbbg1K2kgCkB1bVwyIR9m2L7PRPIhDUIXgGtyKw575yz3lTNs6X4JXnjV+LKM/m3MydnTbtOKIjtz6VhCBq4vSm3ncdrD2lk0VgUXSVKjVDJXJzijW1RQdsU7F77He8u68koNZTz8Oz5yGa6J3H3lZ0xYgXBK2QymlWWA+RWnYhskLBv2vmE+hBMCtbA7KX5drWyRT/2JsqZ2IvfB9Y4bWDNMFbJRFmC9E74SoS0CqulwjkC0+5bpcV1CZ8NMej4pjy0U+doDQsGyo1hzVJttIjhQ7GnBtRFN1UarUlH8F3xict+HY07rEzoUGPlWcjRFRr4/gChZgc3ZL2d8oAAAAASUVORK5CYII='); background-color: #8a6d3b; color: #fcf8e3; border-color: #faebcc; } +.jq-icon-error { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHOSURBVEhLrZa/SgNBEMZzh0WKCClSCKaIYOED+AAKeQQLG8HWztLCImBrYadgIdY+gIKNYkBFSwu7CAoqCgkkoGBI/E28PdbLZmeDLgzZzcx83/zZ2SSXC1j9fr+I1Hq93g2yxH4iwM1vkoBWAdxCmpzTxfkN2RcyZNaHFIkSo10+8kgxkXIURV5HGxTmFuc75B2RfQkpxHG8aAgaAFa0tAHqYFfQ7Iwe2yhODk8+J4C7yAoRTWI3w/4klGRgR4lO7Rpn9+gvMyWp+uxFh8+H+ARlgN1nJuJuQAYvNkEnwGFck18Er4q3egEc/oO+mhLdKgRyhdNFiacC0rlOCbhNVz4H9FnAYgDBvU3QIioZlJFLJtsoHYRDfiZoUyIxqCtRpVlANq0EU4dApjrtgezPFad5S19Wgjkc0hNVnuF4HjVA6C7QrSIbylB+oZe3aHgBsqlNqKYH48jXyJKMuAbiyVJ8KzaB3eRc0pg9VwQ4niFryI68qiOi3AbjwdsfnAtk0bCjTLJKr6mrD9g8iq/S/B81hguOMlQTnVyG40wAcjnmgsCNESDrjme7wfftP4P7SP4N3CJZdvzoNyGq2c/HWOXJGsvVg+RA/k2MC/wN6I2YA2Pt8GkAAAAASUVORK5CYII='); background-color: #a94442; color: #f2dede; border-color: #ebccd1; } +.jq-icon-success { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADsSURBVEhLY2AYBfQMgf///3P8+/evAIgvA/FsIF+BavYDDWMBGroaSMMBiE8VC7AZDrIFaMFnii3AZTjUgsUUWUDA8OdAH6iQbQEhw4HyGsPEcKBXBIC4ARhex4G4BsjmweU1soIFaGg/WtoFZRIZdEvIMhxkCCjXIVsATV6gFGACs4Rsw0EGgIIH3QJYJgHSARQZDrWAB+jawzgs+Q2UO49D7jnRSRGoEFRILcdmEMWGI0cm0JJ2QpYA1RDvcmzJEWhABhD/pqrL0S0CWuABKgnRki9lLseS7g2AlqwHWQSKH4oKLrILpRGhEQCw2LiRUIa4lwAAAABJRU5ErkJggg=='); color: #dff0d8; background-color: #3c763d; border-color: #d6e9c6; } \ No newline at end of file diff --git a/assets/css/style.css b/assets/css/style.css new file mode 100644 index 0000000..bc4a009 --- /dev/null +++ b/assets/css/style.css @@ -0,0 +1,50 @@ +body { + background-color: #d1cbcb; + color: #fff; + text-align: center; + font-family: Arial, sans-serif; +} + +.wrap { + max-width: 600px; + margin: 0 auto; +} + +#recording-button { + background-color: red; + color: white; + border: none; + padding: 20px; + font-size: 20px; + border-radius: 50%; + cursor: pointer; + margin-top: 20px; + width: 100px; + height: 100px; + background-image: url('../img/microphone.png'); /* آدرس تصویر میکروفون */ + background-repeat: no-repeat; + background-position: center; + background-size: 50%; + display: block; + margin: 20px auto; /* برای قرارگیری در وسط صفحه */ +} + +#visualizer { + display: none; + margin-top: 20px; +} + +audio { + display: none; + margin: 20px auto; + width: 300px; +} + +audio.show { + display: block; +} + +canvas { + display: block; + margin: 20px auto; +} diff --git a/assets/img/microphone.png b/assets/img/microphone.png new file mode 100644 index 0000000..11a1f02 Binary files /dev/null and b/assets/img/microphone.png differ diff --git a/assets/js/audio-diary.js b/assets/js/audio-diary.js index 2c691fa..f5a66a0 100644 --- a/assets/js/audio-diary.js +++ b/assets/js/audio-diary.js @@ -1,53 +1,120 @@ jQuery(document).ready(function($) { - var mediaRecorder; - var audioChunks = []; + let mediaRecorder; + let audioChunks = []; + let isRecording = false; + let audioContext, analyser, dataArray, bufferLength, source; - $('#start-recording').on('click', function() { - navigator.mediaDevices.getUserMedia({ audio: true }) - .then(stream => { - mediaRecorder = new MediaRecorder(stream); - mediaRecorder.start(); + function visualize(stream) { + audioContext = new (window.AudioContext || window.webkitAudioContext)(); + analyser = audioContext.createAnalyser(); + source = audioContext.createMediaStreamSource(stream); + source.connect(analyser); + analyser.fftSize = 2048; + bufferLength = analyser.frequencyBinCount; + dataArray = new Uint8Array(bufferLength); - mediaRecorder.addEventListener("dataavailable", event => { - audioChunks.push(event.data); - }); + const canvas = document.getElementById('visualizer'); + const canvasCtx = canvas.getContext('2d'); - mediaRecorder.addEventListener("stop", () => { - const audioBlob = new Blob(audioChunks, { type: 'audio/wav' }); - const audioUrl = URL.createObjectURL(audioBlob); - const audio = document.getElementById('audio-player'); - audio.src = audioUrl; + function draw() { + requestAnimationFrame(draw); + + analyser.getByteTimeDomainData(dataArray); + + canvasCtx.fillStyle = 'rgb(0, 0, 0)'; + canvasCtx.fillRect(0, 0, canvas.width, canvas.height); + + canvasCtx.lineWidth = 2; + canvasCtx.strokeStyle = 'rgb(255, 255, 255)'; + + canvasCtx.beginPath(); + + let sliceWidth = canvas.width * 1.0 / bufferLength; + let x = 0; + + for(let i = 0; i < bufferLength; i++) { + let v = dataArray[i] / 128.0; + let y = v * canvas.height / 2; + + if(i === 0) { + canvasCtx.moveTo(x, y); + } else { + canvasCtx.lineTo(x, y); + } + + x += sliceWidth; + } + + canvasCtx.lineTo(canvas.width, canvas.height / 2); + canvasCtx.stroke(); + } + + draw(); + } + + $('#recording-button').on('click', function() { + if (!isRecording) { + navigator.mediaDevices.getUserMedia({ audio: true }) + .then(stream => { + mediaRecorder = new MediaRecorder(stream); + mediaRecorder.start(); + visualize(stream); + + mediaRecorder.ondataavailable = function(event) { + audioChunks.push(event.data); + }; + + mediaRecorder.onstop = function() { + const audioBlob = new Blob(audioChunks, { type: 'audio/wav' }); + audioChunks = []; + const audioUrl = URL.createObjectURL(audioBlob); + $('#audio-player').attr('src', audioUrl).addClass('show'); + + let formData = new FormData(); + formData.append('audio_data', audioBlob, 'audio.wav'); + formData.append('action', 'save_audio'); - var reader = new FileReader(); - reader.readAsDataURL(audioBlob); - reader.onloadend = function() { - var base64data = reader.result; $.ajax({ - url: audioDiaryJsObject.ajax_url, - method: 'POST', - data: { - action: 'save_audio', - audio_data: base64data, - _wpnonce: audioDiaryJsObject.nonce - }, + url: ajaxurl, + type: 'POST', + data: formData, + processData: false, + contentType: false, success: function(response) { - console.log('Audio saved successfully.'); - }, - error: function() { - console.error('Failed to save audio.'); + if (response.success) { + $.toast({ + text: "Audio saved successfully", // Text that is to be shown in the toast + heading: 'Note', // Optional heading to be shown on the toast + icon: 'success', // Type of toast icon + showHideTransition: 'fade', // fade, slide or plain + allowToastClose: true, // Boolean value true or false + hideAfter: 3000, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden + stack: 3, // false if there should be only one toast at a time or a number representing the maximum number of toasts to be shown at a time + position: 'bottom-left', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values + + + + textAlign: 'left', // Text alignment i.e. left, right or center + loader: true, // Whether to show loader or not. True by default + loaderBg: '#9EC600', // Background color of the toast loader + }); + + } else { + alert('Failed to save audio'); + } } }); }; + + $('#visualizer').show(); + isRecording = true; + $('#recording-button').css('background-color', 'green'); // تغییر رنگ دکمه به سبز برای نشان دادن حالت ضبط }); - - $('#stop-recording').prop('disabled', false); - $('#start-recording').prop('disabled', true); - }); - }); - - $('#stop-recording').on('click', function() { - mediaRecorder.stop(); - $('#stop-recording').prop('disabled', true); - $('#start-recording').prop('disabled', false); + } else { + mediaRecorder.stop(); + $('#visualizer').hide(); + isRecording = false; + $('#recording-button').css('background-color', 'red'); // بازگشت به رنگ قرمز + } }); }); diff --git a/assets/js/jquery.toast.js b/assets/js/jquery.toast.js new file mode 100644 index 0000000..5335a0b --- /dev/null +++ b/assets/js/jquery.toast.js @@ -0,0 +1,372 @@ +// jQuery toast plugin created by Kamran Ahmed copyright MIT license 2015 +if ( typeof Object.create !== 'function' ) { + Object.create = function( obj ) { + function F() {} + F.prototype = obj; + return new F(); + }; +} + +(function( $, window, document, undefined ) { + + "use strict"; + + var Toast = { + + _positionClasses : ['bottom-left', 'bottom-right', 'top-right', 'top-left', 'bottom-center', 'top-center', 'mid-center'], + _defaultIcons : ['success', 'error', 'info', 'warning'], + + init: function (options, elem) { + this.prepareOptions(options, $.toast.options); + this.process(); + }, + + prepareOptions: function(options, options_to_extend) { + var _options = {}; + if ( ( typeof options === 'string' ) || ( options instanceof Array ) ) { + _options.text = options; + } else { + _options = options; + } + this.options = $.extend( {}, options_to_extend, _options ); + }, + + process: function () { + this.setup(); + this.addToDom(); + this.position(); + this.bindToast(); + this.animate(); + }, + + setup: function () { + + var _toastContent = ''; + + this._toastEl = this._toastEl || $('
', { + class : 'jq-toast-single' + }); + + // For the loader on top + _toastContent += ''; + + if ( this.options.allowToastClose ) { + _toastContent += '×'; + }; + + if ( this.options.text instanceof Array ) { + + if ( this.options.heading ) { + _toastContent +='
+
+# How to use
+
+- You can install the plugin via Bower:
+
+ ```js
+ bower install jquery-toast-plugin
+ ```
+
+ or via `npm`
+
+ ```js
+ npm install jquery-toast-plugin
+ ```
+
+ Or directly download the repository and place the content of `dist` wherever you can access them.
+- Include the CSS and JS files.
+- Simply do ```$.toast('Toast message to be shown')``` Of course it would be the world's simplest toast message but believe me **you can do a lot more** with the options.
+
+# Demo
+For some quick demos and a detailed documentation accompanied by the demos for each of the available options can be accessed through http://kamranahmed.info/toast
+
+## Quick usage examples
+**Simple textual toast**
+```javascript
+// Non sticky version
+$.toast("Lorem ipsum dolor sit amet, consectetur adipisicing elit. Hic, consequuntur doloremque eveniet eius eaque dicta repudiandae illo ullam. Minima itaque sint magnam dolorum asperiores repudiandae dignissimos expedita, voluptatum vitae velit.")
+// Sticky version
+$.toast({
+ text : "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Hic, consequuntur doloremque eveniet eius eaque dicta repudiandae illo ullam. Minima itaque sint magnam dolorum asperiores repudiandae dignissimos expedita, voluptatum vitae velit.",
+ hideAfter : false
+})
+```
+
+**Toast using HTML as a text**
+```javascript
+// Non sticky
+$.toast("Let's test some HTML stuff... github")
+// sticky
+$.toast({
+ text : "Remember! You can always introduce your own × HTML and CSS in the toast.",
+ hideAfter : false
+})
+```
+
+**Unordered list elements as the text of toast using array**
+```javascript
+// Non sticky version
+$.toast(["Ubuntu : One of it's kind", "Sublime Text : Productivity unleashed", "HeidiSQL : Just love it", "Github : Just Lovely"])
+// Sticky version
+$.toast({
+ text : ["Ubuntu : One of it's kind", "Sublime Text : Productivity unleashed", "HeidiSQL : Just love it", "Github : Just Lovely"],
+ hideAfter : false
+})
+```
+
+**Changing the animations**
+```javascript
+$.toast({
+ text : "Let's test some HTML stuff... github",
+ showHideTransition : 'slide' // It can be plain, fade or slide
+})
+```
+
+**Changing the formatting**
+```javascript
+$.toast({
+ text : "Let's test some HTML stuff... github",
+ showHideTransition : 'slide', // It can be plain, fade or slide
+ bgColor : 'blue', // Background color for toast
+ textColor : '#eee', // text color
+ allowToastClose : false, // Show the close button or not
+ hideAfter : 5000, // `false` to make it sticky or time in miliseconds to hide after
+ stack : 5, // `fakse` to show one stack at a time count showing the number of toasts that can be shown at once
+ textAlign : 'left', // Alignment of text i.e. left, right, center
+ position : 'bottom-left' // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values to position the toast on page
+})
+```
+
+**Resetting the toast**
+```javascript
+var myToast = $.toast('Some toast that needs to be removed.');
+myToast.reset(); // remove the toast "Some toast that needs to be removed"
+```
+What if I want to reset all the toasts at once? You may ask. Well in that case, you can do the following:
+```javascript
+$.toast().reset('all');
+```
+
+**Updating the toast**
+Suppose, you had shown some toast upon the page, a sticky toast for example and now you want to update the toast. You can do the following
+
+```javascript
+var myToast = $.toast({
+ text : 'Some toast that needs to show the success message after the ajax call.',
+ hideAfter : false,
+ bgColor : '#E01A31'
+});
+
+window.setTimeout(function(){
+ myToast.update({
+ text : 'Updated after a few seconds',
+ bgColor : '#23B65D'
+ });
+}, 5000);
+```
+To learn more about how to use and customize it, head to http://kamranahmed.info/toast. Also you can find a customizer there that will let you modify the look and feel of the toast however you like it.
+
+beforeHide, afterHidden, beforeShow, afterShownFade and Slide show/hide transitions support (More to come)top-left, top-right bottom-left and bottom-right, top-center, bottom-center and mid-center ...sighs! That's a whole lot of options, isn't it? No, you say. Ok then here is the most exciting thing, you can also introduce your own positioning just by passing a simple js object containing { top: - , bottom: -, left: -, right: - } Toast loader has been introduced in the latest version. Check the demo below to see it in action
+$.toast('Here you can put the text of the toast')
+ Loader is enabled by default. In order to disable it or change the color, use the `loader` and `loaderBg` options. Have a look at the demo below
+ +$.toast({
+ heading: 'Information',
+ text: 'Loaders are enabled by default. Use `loader`, `loaderBg` to change the default behavior',
+ icon: 'info',
+ loader: true, // Change it to false to disable loader
+ loaderBg: '#9EC600' // To change the background
+})
+ To generate a most simple toast, all you have to do is
+$.toast('Here you can put the text of the toast')
+ There are different kinds of toast types:
+$.toast({
+ heading: 'Information',
+ text: 'Now you can add icons to generate different kinds of toasts',
+ showHideTransition: 'slide',
+ icon: 'info'
+})
+ $.toast({
+ heading: 'Error',
+ text: 'Report any <a href="https://github.com/kamranahmedse/jquery-toast-plugin/issues">issues</a>',
+ showHideTransition: 'fade',
+ icon: 'error'
+})
+ $.toast({
+ heading: 'Warning',
+ text: 'It is going to be supper easy for you to use ;)',
+ showHideTransition: 'plain',
+ icon: 'warning'
+})
+ $.toast({
+ heading: 'Success',
+ text: 'And these were just the basic demos! Scroll down to check further details on how to customize the output.',
+ showHideTransition: 'slide',
+ icon: 'success'
+})
+ Of course that is not all what you can do using this plugin, there are a lot of other options. Let's start explaining each, one by one
+You should note that, whenever you are going to use options, you have to pass an options object and specify the text as follows:
+ +$.toast({
+ text: 'This will become the toast message'
+})
+ The text can be an array:
+ +$.toast({
+ heading: 'How to contribute?!',
+ text: [
+ 'Fork the repository',
+ 'Improve/extend the functionality',
+ 'Create a pull request'
+ ],
+ icon: 'info'
+})
+ Or put some HTML in the text
+ +$.toast({
+ heading: 'Can I add <em>icons</em>?',
+ text: 'Yes! check this <a href="https://github.com/kamranahmedse/jquery-toast-plugin/commits/master">update</a>.',
+ hideAfter: false,
+ icon: 'success'
+})
+ You can use the heading to set the heading property to set the heading of the toast message
+$.toast({
+ heading: 'Headings',
+ text: 'You can use the `heading` property to specify the heading of the toast message.',
+})
+ There will be times, when you will want to have sticky toasts. To make them sticky, all you have to do is set the hideAfter to false. Here is a sticky toast
+ +$.toast({
+ text: 'Set the `hideAfter` property to false and the toast will become sticky.',
+ hideAfter: false
+})
+ * hideAfter property is basically used to set the timer after which the toast will get hidden. But you can set it to false in order to achieve the sticky toasts.
+ +You can use the property from the above option i.e. hideAfter to change the timer after which toast gets hidden. You have to specify the timer in milliseconds
+ +$.toast({
+ text: 'Set the `hideAfter` property to milliseconds and the toast will hide after the specified milli seconds.',
+ hideAfter: 5000 // in milli seconds
+})
+ You can use showHideTransition property to set the animation. Following are the available options:
+$.toast({
+ text: 'Set the `showHideTransition` property to fade|plain|slide to achieve different transitions',
+ heading: 'Slide transition',
+ showHideTransition: 'slide'
+})
+ $.toast({
+ text: 'Set the `showHideTransition` property to fade|plain|slide to achieve different transitions',
+ heading: 'Fade transition',
+ showHideTransition: 'fade'
+})
+ $.toast({
+ text: 'Set the `showHideTransition` property to fade|plain|slide to achieve different transitions',
+ heading: 'Plain transition',
+ showHideTransition: 'plain'
+})
+ You can use allowToastClose to allow the user to close the toast or not. The only thing that this option does is make that little cross button show or hide itself
+ +$.toast({
+ heading: 'Closeable Toast',
+ text: 'Set the `allowToastClose` property to true|false to make the toast closeable or not',
+ allowToastClose: true
+})
+ $.toast({
+ heading: 'Non closeable Toast',
+ text: 'Set the `allowToastClose` property to true|false to make the toast closeable or not',
+ allowToastClose: false
+})
+ stack property can be used to specify how many maximum toasts you want to show at any point of time. By default this property is set to 5
+ +$.toast({
+ heading: 'Stack',
+ text: 'If set to a number, it will show that number of toasts at max at a time',
+ stack: 4
+})
+ $.toast({
+ heading: 'No stacking',
+ text: 'If set to false, there will be only one toast at once.',
+ stack: false
+})
+ Note Hit the run button multiple times to test these demos.
+ +position property can be used to specify the position. There are following predefined positions which you can use:
+$.toast().reset('all');$.toast({
+ heading: 'Positioning',
+ text: 'Specify the custom position object or use one of the predefined ones',
+ position: 'bottom-left',
+ stack: false
+})
+ $.toast().reset('all');$.toast({
+ heading: 'Positioning',
+ text: 'Specify the custom position object or use one of the predefined ones',
+ position: 'bottom-right',
+ stack: false
+})
+ $.toast().reset('all');$.toast({
+ heading: 'Positioning',
+ text: 'Use the predefined ones, or specify a custom object',
+ position: 'bottom-center',
+ stack: false
+})
+ $.toast().reset('all');$.toast({
+ heading: 'Positioning',
+ text: 'Use the predefined ones, or specify a custom object',
+ position: 'top-left',
+ stack: false
+})
+ $.toast().reset('all');$.toast({
+ heading: 'Positioning',
+ text: 'Use the predefined ones, or specify a custom position object.',
+ position: 'top-right',
+ stack: false
+})
+ $.toast().reset('all');$.toast({
+ heading: 'Positioning',
+ text: 'Use the predefined ones, or specify a custom position object.',
+ position: 'top-center',
+ stack: false
+})
+ $.toast().reset('all');$.toast({
+ heading: 'Positioning',
+ text: 'Use the predefined ones, or specify a custom position object.',
+ position: 'mid-center',
+ stack: false
+})
+ $.toast().reset('all');$.toast({
+ heading: 'Positioning',
+ text: 'Use the predefined ones, or specify a custom position object.',
+ position: {
+ left: 120,
+ top: 120
+ },
+ stack: false
+})
+ Note It should be noted that, once you change the position of toast by using the `position` property, you'll have to reset the position for the next toasts, if you want them to appear at their default position i.e. the bottom left corner. Or else, each new toast generated will be appearing at the last position i.e. where you displayed the last positioned toast. You can reset the toast position by.
+ +$.toast().reset('all');
+ icon property can be used to specify the predefined types of toasts. Following are the predefined types:
+$.toast({
+ heading: 'Warning',
+ text: 'Now you can seemlessly generate warnings using the icon property in the options',
+ icon: 'warning'
+})
+ $.toast({
+ heading: 'Success',
+ text: 'Here is some kind of success message with a success icon that you can notice at the left side.',
+ icon: 'success'
+})
+ $.toast({
+ heading: 'Error',
+ text: 'An unexpected error occured while trying to show you the toast! ..Just kidding, it is just a message, toast is right in front of you.',
+ icon: 'error'
+})
+ $.toast({
+ heading: 'Information',
+ text: 'Now you can add icons to the toasts as well.',
+ icon: 'info'
+})
+ bgColor property is used to specify the background color of the toast message. Default is '#444'
+textColor property is used to specify the text color of the toast message. Default is '#eee'
+ +$.toast({
+ heading: 'Colors',
+ text: 'Colors are specified using `bgColor` and `textColor` properties.',
+ bgColor: '#FF1356',
+ textColor: 'white'
+})
+ textAlign property is used to set the alignment of text inside the toast. Permitted values are:
+$.toast({
+ text: 'Processing! Please wait..',
+ textAlign: 'center'
+})
+ class property is used to add custom classes to the toast element
+ + +$.toast({
+ heading: 'Custom Classes',
+ text: 'Custom classes are specified using the `class` option.',
+ class: 'larger-font'
+})
+ Toast exposes the following events for you to bind to whatever you want
+$.toast({
+ text: 'Triggers the events',
+
+ beforeShow: function () {
+ alert('The toast is about to appear');
+ },
+
+ afterShown: function () {
+ alert('Toast has appeared.');
+ },
+
+ beforeHide: function () {
+ alert('Toast is about to hide.');
+ },
+
+ afterHidden: function () {
+ alert('Toast has been hidden.');
+ }
+})
+ If you have a reference to a toast and want to update that, you can do so by calling the update method on the instance.
+ +
+var myToast = $.toast({
+ heading: 'Information',
+ text: 'Here is some information that will be later on turned to an error',
+ icon: 'info',
+ hideAfter: false
+});
+
+// Update the toast after three seconds.
+window.setTimeout(function(){
+ myToast.update({
+ heading: 'Error',
+ text: 'Here is an information that changed to error',
+ icon: 'error',
+ hideAfter: false
+ });
+}, 3000)
+
+
+ If you have the reference to a specific toast, you can reset that by doing the following
+ +
+var myToast = $.toast('Some toast that needs to be removed.');
+myToast.reset(); // remove the toast "Some toast that needs to be removed"
+
+ If you do not have the reference to a specific toast and want to reset every toast, do the following:
+
+$.toast().reset('all');
+
+