Advertisement
Guest User

Untitled

a guest
Apr 25th, 2012
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. New Perspectives on JavaScript, 2nd Edition
  3. Tutorial 6
  4. Case Problem 2
  5. Author: Kenneth Hitchcock
  6. Date: 6/16/2011
  7. Filename: flibrary.js
  8. Functions List:
  9. getStyle(object, styleName)
  10. Returns the computed style value for a specified styleName applied to
  11. an object.
  12. addEvent(object, evName, fnName, cap)
  13. Assigns an event handers to object where evName is the name of the event,
  14. fnName is the name of the function, and cap is the capture phase.
  15. This function works for both the IE and W3C event models.
  16. removeEvent(object, evName, fnName, cap)
  17. Removes an event handers from object where evName is the name of the event,
  18. fnName is the name of the function, and cap is the capture phase.
  19. This function works for both the IE and W3C event models.
  20. */
  21. function getStyle(object, styleName) {
  22. if (window.getComputedStyle) {
  23. return document.defaultView.getComputedStyle(object, null).getPropertyValue(styleName);
  24. } else if (object.currentStyle) {
  25. return object.currentStyle[styleName]
  26. }
  27. }
  28. /*
  29. Assigns an event handers to object where evName is the name of the event,
  30. fnName is the name of the function, and cap is the capture phase.
  31. This function works for both the IE and W3C event models.
  32. */
  33. function addEvent(object, evName, fnName, cap)
  34. {
  35. if (object.attachEvent)
  36. {
  37. object.attachEvent("on" + evName, fnName);
  38. }
  39. else if (object.addEventListener)
  40. {
  41. object.addEventListener(evName, fnName, cap);
  42. }
  43. }
  44. /*
  45. Removes an event handers from object where evName is the name of the event,
  46. fnName is the name of the function, and cap is the capture phase.
  47. This function works for both the IE and W3C event models.
  48. */
  49. function removeEvent(object, evName, fnName, cap)
  50. {
  51. if (object.detachEvent)
  52. {
  53. object.detachEvent("on" + evName, fnName);
  54. }
  55. else if (object.removeEventListener)
  56. {
  57. object.removeEventListener(evName, fnName, cap);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement