{"_id":"jquery.are-you-sure","_rev":"1-497b27469b140822769ce5a96862a96f","name":"jquery.are-you-sure","description":"A light-weight jQuery \"dirty forms\" Plugin - it monitors HTML forms and alerts users to unsaved changes if they attempt to close the browser or navigate away from the page. (Are you sure?)","dist-tags":{"latest":"1.9.0"},"versions":{"1.9.0":{"name":"jquery.are-you-sure","description":"A light-weight jQuery \"dirty forms\" Plugin - it monitors HTML forms and alerts users to unsaved changes if they attempt to close the browser or navigate away from the page. (Are you sure?)","homepage":"https://github.com/codedance/jquery.AreYouSure","author":{"name":"Chris Dance","email":"chris.dance@papercut.com","url":"https://github.com/codedance"},"contributors":[{"name":"Tom Clift","email":"tom.clift@papercut.com","url":"https://github.com/tclift"},{"name":"Jon Egerton","email":"jon@ja2.co.uk","url":"http://www.jonegerton.com/"},{"name":"Scadoodles","url":"https://github.com/Scadoodles"},{"name":"Albin Sunnanbo","url":"https://github.com/albinsunnanbo"},{"name":"Marc Sutton","email":"ashre@iname.com","url":"http://www.codev.co.uk"}],"version":"1.9.0","license":"MIT/GPLv2","keywords":["dirty","form","onbeforeunload","save","check"],"main":"jquery.are-you-sure.js","engines":{"node":">=0.8.0"},"repository":{"type":"git","url":"git+https://github.com/codedance/jquery.AreYouSure.git"},"bugs":{"url":"https://github.com/codedance/jquery.AreYouSure/issues"},"dependencies":{"jquery":">=1.4.2"},"devDependencies":{"bower":"^1.3.1","grunt":"^0.4.5","grunt-cli":"^0.1.13","grunt-karma":"^0.8.3","karma-chrome-launcher":"^0.1.4","karma-jasmine":"^0.2.2","karma-ie-launcher":"^0.1.5","karma-firefox-launcher":"^0.1.3","karma-safari-launcher":"^0.1.1"},"scripts":{"test":"grunt test"},"gitHead":"5fed00c340a11e6b3f640896201034118992aaac","_id":"jquery.are-you-sure@1.9.0","_npmVersion":"5.5.1","_nodeVersion":"6.11.4","_npmUser":{"name":"srottem","email":"s.rottem@gmail.com"},"dist":{"integrity":"sha512-2r0uFx8CyAopjeHGOdvvwpFP921TnW1+v1uJXcAWQYHYGB1tryTDhQY+5u6HsVeMwbWiRTKVZFWnLaFpDvIqZQ==","shasum":"16aaa2c6080fa214f64027239ae3a34ad6a6265e","tarball":"https://registry.npmjs.org/jquery.are-you-sure/-/jquery.are-you-sure-1.9.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE9PmL8B5M+cXsKS55u7YNvi7JY8fkaJx122fMR6ovcFAiEAtn3w5rbuQRJ+A7LC2CetN5ck18BqDGIe0rD+DKIf28A="}]},"maintainers":[{"name":"srottem","email":"s.rottem@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jquery.are-you-sure-1.9.0.tgz_1508788792972_0.2981240141671151"}}},"readme":"Are You Sure? - A light \"dirty forms\" JQuery Plugin\r\n======\r\n**Version:** 1.9\r\n\r\n*Are-you-sure* (```jquery.are-you-sure.js```) is simple light-weight \"dirty \r\nform\" JQuery Plugin for modern browsers.  It helps prevent users from losing \r\nunsaved HTML Form changes by promoting the user to save/submit.\r\n\r\nIt's simple to use.  Just add the following line to your page's ready \r\nfunction:\r\n\r\n```javascript\r\n$('form').areYouSure();\r\n```\r\n\r\n*Are-you-sure* is a minimal plugin for modern browsers.  There are plenty of \r\n\"dirty forms\" implementations out there, however they all seemed very \r\nheavyweight and over-engineered...! Most were written some time back and \r\ncontain many 'hacks' to support legacy browsers, and/or rely on other fat \r\ndependencies such as FaceBox or jQueryUI.  *Are-you-sure* solves this by\r\ndoing this simple task in the simplest possible way.\r\n\r\n*Are-you-sure* is as simple as it gets:\r\n\r\n * 100% JS with zero dependencies and no external CSS.\r\n * Leverages `onBeforeUnload` to detect all page/browser exit events.\r\n * Works on forms of any size.\r\n * Correct state management - if a user edits then restores a value, the form \r\n   is not considered dirty.\r\n * Easy to understand - less than a \"terminal screen\" of code!\r\n * Graceful degradation on legacy browsers (i.e. if you're running an old \r\n   browser... remember to save :-)\r\n\r\n###Basic Usage\r\n\r\n```javascript\r\n\r\n$(function() {\r\n\r\n    // Enable on all forms\r\n    $('form').areYouSure();\r\n\r\n    // Enable on selected forms\r\n    $('form.dirty-check').areYouSure();\r\n\r\n    // With a custom message\r\n    $('form').areYouSure( {'message':'Your profile details are not saved!'} );\r\n\r\n}\r\n```\r\nTo ignore selected fields from the dirtyness check: \r\n\r\n```html\r\n  <form id=\"myForm\" name=\"myform\" action=\"/post\" method=\"post\">\r\n\r\n    Field 1: (checked)  <input type=\"text\" name=\"field1\"> <br />\r\n    Field 2: (ignored): <input type=\"text\" name=\"field2\" data-ays-ignore=\"true\"> <br />\r\n    Field 3: (ignored): <input type=\"text\" name=\"field3\" class=\"ays-ignore\"> <br />\r\n\r\n    <input type=\"submit\" value=\"Submit\">\r\n\r\n  </form>\r\n```\r\n\r\n###Advanced Usage\r\n\r\n```javascript\r\n\r\n$(function() {\r\n\r\n    /*\r\n    *  Make Are-You-Sure \"silent\" by disabling the warning message \r\n    *  (tracking/monitoring only mode). This option is useful when you wish to \r\n    *  use the dirty/save events and/or use the dirtyness tracking in your own \r\n    *  beforeunload handler.\r\n    */\r\n    $('form').areYouSure( {'silent':true} );\r\n\t\r\n    /*\r\n    *  Dirtyness Change Events\r\n    *  Are-You-Sure fires off \"dirty\" and \"clean\" events when the form's state\r\n    *  changes. You can bind() or on(), these events to implement your own form\r\n    *  state logic.  A good example is enabling/disabling a Save button.\r\n    *\r\n    *  \"this\" refers to the form that fired the event.\r\n    */\r\n    $('form').on('dirty.areYouSure', function() {\r\n      // Enable save button only as the form is dirty.\r\n      $(this).find('input[type=\"submit\"]').removeAttr('disabled');\r\n    });\r\n    $('form').on('clean.areYouSure', function() {\r\n      // Form is clean so nothing to save - disable the save button.\r\n      $(this).find('input[type=\"submit\"]').attr('disabled', 'disabled');\r\n    });\r\n\r\n    /*\r\n    *  It's easy to test if a form is dirty in your own code - just check\r\n    *  to see if it has a \"dirty\" CSS class.\r\n    */\r\n    if ($('#my-form').hasClass('dirty')) {\r\n        // Do something\r\n    }\r\n\r\n    /*\r\n    *  If you're dynamically adding new fields/inputs, and would like to track \r\n    *  their state, trigger Are-You-Sure to rescan the form like this:\r\n    */\r\n    $('#my-form').trigger('rescan.areYouSure');\r\n\r\n    /*\r\n    *  If you'd like to reset/reinitialize the form's state as clean and \r\n    *  start tracking again from this new point onwards, trigger the\r\n    *  reinitalize as follows. This is handy if say you've managing your\r\n    *  own form save/submit via asyc AJAX.\r\n    */\r\n    $('#my-form').trigger('reinitialize.areYouSure');\r\n\r\n    /*\r\n    *  In some situations it may be desirable to look for other form\r\n    *  changes such as adding/removing fields. This is useful for forms that\r\n    *  can change their field count, such as address/phone contact forms.\r\n    *  Form example, you might remove a phone number from a contact form\r\n    *  but update nothing else. This should mark the form as dirty.\r\n    */\r\n    $('form').areYouSure( {'addRemoveFieldsMarksDirty':true} );\r\n    \r\n    /*\r\n    *  Sometimes you may have advanced forms that change their state via\r\n    *  custom JavaScript or 3rd-party component JavaScript. Are-You-Sure may \r\n    *  not automatically detect these state changes. Examples include:\r\n    *     - Updating a hidden input field via background JS.\r\n    *     - Using a [rich WYSIWYG edit control](https://github.com/codedance/jquery.AreYouSure/issues/17).\r\n    *  One solution is to manually trigger a form check as follows:\r\n    */\r\n    $('#my-form').trigger('checkform.areYouSure');\r\n\t\r\n    /*\r\n    *  As an alternative to using events, you can pass in a custom change \r\n    *  function.\r\n    */\r\n    $('#my-adv-form').areYouSure({\r\n        change: function() {\r\n              // Enable save button only if the form is dirty. i.e. something to save.\r\n              if ($(this).hasClass('dirty')) {\r\n                $(this).find('input[type=\"submit\"]').removeAttr('disabled');\r\n              } else {\r\n                $(this).find('input[type=\"submit\"]').attr('disabled', 'disabled');\r\n              }\r\n            }\r\n    });\r\n\r\n    /*\r\n    *  Mixing in your own logic into the warning.\r\n    */\r\n    $('#my-form').areYouSure( {'silent':true} );\r\n    $(window).on('beforeunload', function() {\r\n        isSunday = (0 == (new Date()).getDay());\r\n        if ($('#my-form').hasClass('dirty') && isSunday) {\r\n            return \"Because it's Sunday, I'll be nice and let you know you forgot to save!\";\r\n        }\r\n    }\r\n    \r\n}\r\n```\r\nThe [demo page](http://www.papercut.com/products/free_software/are-you-sure/demo/are-you-sure-demo.html)\r\nshows the advanced usage options in more detail.\r\n\r\n\r\n###Install\r\nAre-You-Sure is a light-weight jQuery plugin - it's a single standalone \r\nJavaScript file. You can download the \r\n[jquery.are-you-sure.js](https://raw.github.com/codedance/jquery.AreYouSure/master/jquery.are-you-sure.js)\r\nfile and include it in your page. Because it's so simple it seems a shame \r\nto add an extra browser round trip. It's recommended that you consider\r\nconcatenating it with other common JS lib files, and/or even cut-n-pasting \r\nthe code (and license header) into one of your existing JS files.\r\n\r\nFor experimental Mobile Safari support, also include ```ays-beforeunload-shim.js``` \r\n(see Known Issues below).\r\n\r\n*Are-you-sure* may also be installed with [Bower](http://twitter.github.com/bower/):\r\n\r\n```bash\r\n$ bower install jquery.are-you-sure\r\n```\r\n\r\nIf you're using, or like, *Are-you-sure* make sure you **star/watch** this project\r\nso you can stay up-to-date with updates.\r\n\r\n###Demo\r\nThis [demo page](http://www.papercut.com/products/free_software/are-you-sure/demo/are-you-sure-demo.html)\r\nhosts a number of example forms.\r\n\r\n###Supported Browsers\r\n*Are-you-sure* has been tested on and fully supports the following browsers:\r\n\r\n* IE 9 through 11\r\n* Google Chrome (versions since 2012)\r\n* Firefox (versions since 2012)\r\n* Safari (versions since 2012)\r\n\r\nExperimental support is available on iOS and Opera via the *beforeunload* shim (see below).\r\n\r\n###Known Issues & Limitations\r\n\r\n####Mobile Safari and Opera\r\nThe ```windows.beforeunload``` event is not supported on iOS (iPhone, iPad, and iPod). An\r\nexperimental shim offering partial *beforeunload* emulation is provided to help plug this gap.\r\nIt works by scanning the page for anchor links and augments the default behaviour to first\r\ncheck with *Are-you-sure* before navigating away. To use, simply include \r\n```ays-beforeunload-shim.js``` in your page.\r\n\r\n####Firefox\r\nThe custom message option may not work on Firefox ([Firefox bug 588292](https://bugzilla.mozilla.org/show_bug.cgi?id=588292)).\r\n\r\n###Development\r\nThe aim is to keep *Are-you-sure* simple and light. If you think you have \r\na good idea which is aligned with this objective, please voice your thoughts \r\nin the issues list.\r\n\r\n####Pull Requests\r\nIf possible, please submit your pull request against the most recent ```dev-*``` branch rather than master. This will make it easier to merge your code into the next planned release.\r\n\r\n####Running tests\r\n```bash\r\n$ npm install\r\n$ npm test\r\n```\r\n\r\n###Release History\r\n\r\n**2014-08-13** (1.9) - This is a minor bugfix release:\r\n\r\n* Addressed issue [#45](https://github.com/codedance/jquery.AreYouSure/issues/55) seen with empty select fields.\r\n* Thanks [valgen](https://github.com/valgen) and [tus124](https://github.com/tus124) for the contribution.\r\n\r\n**2014-06-22** (1.8) - This is a minor bugfix release:\r\n\r\n* Fixed NPE that may occur when using a 'multiple' option field.\r\n* Minor timing tweak to help mitigate bypass issue raised in [#45](https://github.com/codedance/jquery.AreYouSure/issues/45)\r\n* Thanks [apassant](https://github.com/apassant) and [amatenkov](https://github.com/amatenkov) for the contribution.\r\n\r\n**2014-05-28** (1.7)\r\n\r\n* Fixed multiple warning dialogs that may appear on IE and recent versions of Chrome\r\n* Experimental support for iOS Mobile Safari (via a *beforeunload* shim)\r\n* Various minor fixes (e.g. support input fields with no type=)\r\n* Minor performance improvements on pages with multiple forms\r\n* Improved documentation and examples\r\n* Thanks to [lfjeff](https://github.com/lfjeff) and [aqlong](https://github.com/aqlong) for the contribution and ideas!\r\n\r\n**2014-02-07** (1.6)\r\n\r\n* Add field count tracking (```addRemoveFieldsMarksDirty```) (contrib *jonegerton*)\r\n* Added event to manually trigger a form check/recheck  (contrib *jonegerton*)\r\n* Thanks to [jonegerton](https://github.com/jonegerton) for the contribution!\r\n\r\n**2013-11-15** (1.5)\r\n\r\n* Added support for HTML5 input field types. (contrib *albinsunnanbo*)\r\n* New option to reinitialize/reset the dirty state.  This is handy if you're managing your own async submit/save using AJAX. (contrib *albinsunnanbo*)\r\n* Thanks to [albinsunnanbo](https://github.com/albinsunnanbo) for the contribution!\r\n\r\n**2013-10-2** (1.4)\r\n\r\n* Added dirty and clean \"events\" \r\n* Added an option to disable the message (dirty tracking only)\r\n* Added an option to rescan a form to look/detect any new fields\r\n\r\n**2013-07-24** - Minor fix - don't fail if form elements have no \"name\" attribute.\r\n\r\n**2013-05-14** - Added support for form reset buttons (contributed by codev).\r\n\r\n**2013-05-01** - Added support for hidden and disabled form fields.\r\n\r\n**2013-02-03** - Add demo page.\r\n\r\n**2013-01-28** - Add ```change``` event support and a demo page.\r\n\r\n**2012-10-26** - Use dashes in class names rather than camel case.\r\n\r\n**2012-10-24** - Initial public release.\r\n\r\n\r\n###Prerequisites\r\njQuery version 1.4.2 or higher. 2.0+ or 1.10+ recommended.\r\n\r\n\r\n###License\r\nThe same as JQuery...\r\n\r\n    jQuery Plugin: Are-You-Sure (Dirty Form Detection)\r\n    https://github.com/codedance/jquery.AreYouSure/\r\n \r\n    Copyright (c) 2012-2014, Chris Dance - PaperCut Software http://www.papercut.com/\r\n    Dual licensed under the MIT or GPL Version 2 licenses.\r\n    http://jquery.org/license\r\n","maintainers":[{"name":"srottem","email":"s.rottem@gmail.com"}],"time":{"modified":"2022-05-06T17:48:17.435Z","created":"2017-10-23T19:59:53.850Z","1.9.0":"2017-10-23T19:59:53.850Z"},"homepage":"https://github.com/codedance/jquery.AreYouSure","keywords":["dirty","form","onbeforeunload","save","check"],"repository":{"type":"git","url":"git+https://github.com/codedance/jquery.AreYouSure.git"},"contributors":[{"name":"Tom Clift","email":"tom.clift@papercut.com","url":"https://github.com/tclift"},{"name":"Jon Egerton","email":"jon@ja2.co.uk","url":"http://www.jonegerton.com/"},{"name":"Scadoodles","url":"https://github.com/Scadoodles"},{"name":"Albin Sunnanbo","url":"https://github.com/albinsunnanbo"},{"name":"Marc Sutton","email":"ashre@iname.com","url":"http://www.codev.co.uk"}],"author":{"name":"Chris Dance","email":"chris.dance@papercut.com","url":"https://github.com/codedance"},"bugs":{"url":"https://github.com/codedance/jquery.AreYouSure/issues"},"license":"MIT/GPLv2","readmeFilename":"README.md"}