PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/documentation/appframework/$.cleanUpContent.md

https://github.com/maoyao/appframework
Markdown | 61 lines | 43 code | 18 blank | 0 comment | 0 complexity | eedd97c6c142aa9172bd6e757f55db4f MD5 | raw file
  1. #$.cleanUpContent(node,itself,kill)
  2. ```
  3. Function to clean up node content to prevent memory leaks
  4. ```
  5. ##Example
  6. ```
  7. $.cleanUpContent(node,itself,kill)
  8. ```
  9. ##Parameters
  10. ```
  11. node HTMLNode
  12. kill Bool
  13. Kill bool
  14. ```
  15. ##Returns
  16. ```
  17. undefined
  18. ```
  19. ##Detail
  20. $.cleanUpContent(node,[itself],[kill]) traverses through the dom and tries to de-regster any event listeners to prevent memory leaks.
  21. This is called internally by $().html() and $().empty(). It does slow down those operations, but the gain is worth it.
  22. Below is the code for $().html() to show how we use it
  23. ```
  24. html: function (html, cleanup) {
  25. if (this.length === 0)
  26. return this;
  27. if (html ===nundefined)
  28. return this[0].innerHTML;
  29. for (var i = 0; i < this.length; i++) {
  30. if (cleanup !== false)
  31. $.cleanUpContent(this[i], false, true);
  32. if(isWin8)
  33. {
  34. MSApp.execUnsafeLocalFunction(function(){
  35. this[i].innerHTML=html;
  36. });
  37. }
  38. else
  39. this[i].innerHTML = html;
  40. }
  41. return this;
  42. },
  43. ```