
![]() |
perkiset
This little class was modelled (but is not precisely) after the
observerpattern. The notion here is that I often have lots of elements on a page that a user *might* edit... and I don't want to leave the page if the page is "dirty."So, I instantiate one of these classes on a page, then register anything that might get edited by the user (and Im concerned about) with it. I also trap the leaving a page event and check this, so that if a user is editing some content on a web page, for example, and they browser elsewhere I can throw up a " ![]() ajaxapp looks more like a real application.Here's the code - ping me if you need to see it in action: Enjoy! /p // ----------------------------------------------------------- // // dirtyElement // // ----------------------------------------------------------- // function dirtyElement() { this.clear(); } dirtyElement.prototype.clear = function() { this.dirtyList = new Array(); this.dirtyIDX = new Array(); this.onChange = null; this.isDirtyAny = false; } dirtyElement.prototype.clearDirty = function(theName) { this.dirtyList[theName] = false; this.isDirtyAny = false; for (var i=0; i<this.dirtyIDX.length; i++) { var thisName = this.dirtyIDX<>; if (this.dirtyList[thisName]) { this.isDirtyAny = true; } } if ( (!this.isDirtyAny) && (this.onChange) ) { this.onChange(false, theName); } } dirtyElement.prototype.clearDirtyAll = function() { for (var i=0; i<this.dirtyIDX.length; i++) { var thisName = this.dirtyIDX<>; this.dirtyList[thisName] = false; } if (this.onChange) { this.onChange(false); } this.isDirtyAny = false; } dirtyElement.prototype.dirty = function(theName) { if ( (!this.isDirty(theName)) && (this.onChange)) { this.onChange(true, theName); } this.dirtyList[theName] = true; this.isDirtyAny = true; } dirtyElement.prototype.isDirty = function(theName) { return this.dirtyList[theName]; } dirtyElement.prototype.proceed = function(theName, theMsg) { if (this.isDirty(theName)) { return confirm(theMsg); } else return true; } dirtyElement.prototype.proceedAny = function(theMsg) { if (this.isDirtyAny) { ok2Go = confirm(theMsg); if (ok2Go) { this.clearDirtyAll(); } return ok2Go; } else return true; } dirtyElement.prototype.watch = function(theName) { this.dirtyList[theName] = false; var ptr = this.dirtyIDX.length; this.dirtyIDX[ptr] = theName; } // ----------------------------------------------------------- // // dirtyElement // // ----------------------------------------------------------- // function dirtyElement() { this.clear(); } dirtyElement.prototype.clear = function() { this.dirtyList = new Array(); this.dirtyIDX = new Array(); this.onChange = null; this.isDirtyAny = false; } dirtyElement.prototype.clearDirty = function(theName) { this.dirtyList[theName] = false; this.isDirtyAny = false; for (var i=0; i<this.dirtyIDX.length; i++) { var thisName = this.dirtyIDX<>; if (this.dirtyList[thisName]) { this.isDirtyAny = true; } } if ( (!this.isDirtyAny) && (this.onChange) ) { this.onChange(false, theName); } } dirtyElement.prototype.clearDirtyAll = function() { for (var i=0; i<this.dirtyIDX.length; i++) { var thisName = this.dirtyIDX<>; this.dirtyList[thisName] = false; } if (this.onChange) { this.onChange(false); } this.isDirtyAny = false; } dirtyElement.prototype.dirty = function(theName) { if ( (!this.isDirty(theName)) && (this.onChange)) { this.onChange(true, theName); } this.dirtyList[theName] = true; this.isDirtyAny = true; } dirtyElement.prototype.isDirty = function(theName) { return this.dirtyList[theName]; } dirtyElement.prototype.proceed = function(theName, theMsg) { if (this.isDirty(theName)) { return confirm(theMsg); } else return true; } dirtyElement.prototype.proceedAny = function(theMsg) { if (this.isDirtyAny) { ok2Go = confirm(theMsg); if (ok2Go) { this.clearDirtyAll(); } return ok2Go; } else return true; } dirtyElement.prototype.watch = function(theName) { this.dirtyList[theName] = false; var ptr = this.dirtyIDX.length; this.dirtyIDX[ptr] = theName; } |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads