Skip to content

Commit

Permalink
1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
John Antoni Griffiths committed Jan 12, 2011
1 parent d53d6a3 commit 8fbcd2a
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions jquery.tamper.min.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
/*
* jquery.tamper.js
* v 1.2
*
* Initial Author
* John Griffiths
*
* Description
* Simply watches an element for changes, if any encountered flips the tamper flag to true.
* If the exit button is clicked and the tamper flag is set to true a dialog will appear warning
* the user they will lose their changes if they click OK.
*
* Params:
* watchName : (required) element (textarea) to watch for changes
* exitName : (required) element (button) which classes as an exit when clicked
* messageText : (optional) text to show in the alert dialog
*
* PLEASE NOTE: if an onclick event is present on the exit element it will clone it, remove it
* and append it so when the user click's ok it fires.
*
* Requires: jQuery v1.3+
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
(function(a){a.fn.tamper=function(d,c){var e=a(this),b=a(d);c=c||"Are you sure? \nDoing so will lose any pending changes.";e.data("altered",false);b.data("tamper",{watch:this,message:c});if(typeof b.attr("onclick")=="function"){var h=b.attr("onclick");b.removeAttr("onclick")}e.keypress(function(){a(this).data("altered",true)});b.click(function(){var f=true,g=a(this).data("tamper").watch;if(g=a(g).data("altered")||false){var i=a(this).data("tamper").message;if(confirm(i)===false)f=false}f===true|g=== false&&h&&b.attr("onclick",h);return f})};a.fn.tamperAlert=function(d){var c=a(this);d=d||"Are you sure? \nDoing so will lose any pending changes.";c.data("tamper",{message:d});c.click(function(){var e=true,b=a(this).data("tamper").message;if(a(this).data("altered"))if(confirm(b)===false)e=false;return e})};a.fn.tamperFlag=function(){a(this).data("altered",true)}})(jQuery);
* jquery.tamper.js
* v 1.3
*
* Initial Author
* John Griffiths
*
* Description
* Simply watches an element for changes, if any encountered flips the tamper flag to true.
* If the exit button is clicked and the tamper flag is set to true a dialog will appear warning
* the user they will lose their changes if they click OK.
*
* Params:
* $(element) : (required) element (textarea) to watch for changes
* exitName : (required) element (button) which classes as an exit when clicked
* messageText : (optional) text to show in the alert dialog
*
* Example:
* $("element_to_watch").tamper(exitName, messageText)
*
* PLEASE NOTE: if an onclick event is present on the exit element it will clone it, remove it
* and append it so when the user click's ok it fires.
*
* v1.3 added support for TinyMCE to the 'tamper' function, if any elements have a class of
* .tinymce then it will use tinyMCE's .isDirty() method on-click for any changes. if it returns
* true then data has changed. Uses .each to support multiple tinyMCE controls on the page.
*
* Requires: jQuery v1.3+
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
(function (a) { a.fn.tamper = function (d, c) { var e = a(this), b = a(d); c = c || "Are you sure? \nDoing so will lose any pending changes."; e.data("altered", false); b.data("tamper", { watch: this, message: c }); if (typeof b.attr("onclick") == "function") { var j = b.attr("onclick"); b.removeAttr("onclick") } e.keypress(function () { a(this).data("altered", true) }); b.click(function () { var g = true, f = a(this).data("tamper").watch, h = a(f).data("altered") || false; if (a(f).filter(".tinymce").length > 0) { var i = false; a(tinyMCE.editors).each(function () { if (this.isDirty()) i = true }); if (i) h = i } if (h) { f = a(this).data("tamper").message; if (confirm(f) === false) g = false } g === true | h === false && j && b.attr("onclick", j); return g }) }; a.fn.tamperAlert = function (d) { var c = a(this); d = d || "Are you sure? \nDoing so will lose any pending changes."; c.data("tamper", { message: d }); c.click(function () { var e = true, b = a(this).data("tamper").message; if (a(this).data("altered")) if (confirm(b) === false) e = false; return e }) }; a.fn.tamperFlag = function () { a(this).data("altered", true) } })(jQuery);

0 comments on commit 8fbcd2a

Please sign in to comment.