Guest User

Untitled

a guest
Jun 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. /* global YUI */
  2. YUI.add("my-module", function (Y) {
  3. "use strict";
  4.  
  5. Y.MyWidget = Y.Base.create("my-module", Y.Widget, [], {
  6. initializer: function () {
  7. // publish any events
  8. // do any instantiation that doesn't require DOM
  9. },
  10. renderUI: function () {
  11. // create all DOM nodes
  12. var title = Y.Node.create("<div></div>"),
  13. button = Y.Node.create("<div>Click Me!</div>");
  14.  
  15. // use this.getClassName(arg1s...) to create unque classes
  16. title.addClass(this.getClassName("title"));
  17. button.addClass(this.getClassName("button"));
  18.  
  19. // add nodes to the page all at once
  20. this.get("contentBox").append(Y.all([title, button]));
  21.  
  22. // store shortcuts for DOM you'll need to reference
  23. this._titleNode = title;
  24. this._buttonNode = button;
  25. },
  26. bindUI: function () {
  27. // store references to event handlers you set on other
  28. // objects for clean up later
  29. this._buttonClickHandler = this._buttonNode.on("click", function (event) {
  30. Y.log("you clicked the button!");
  31. event.halt();
  32. }, this);
  33. // assign listeners to events on the instance directly
  34. // they're cleaned up automatically
  35. this.after("titleChange", this._afterTitleChange, this);
  36. },
  37. _afterTitleChange: function (event) {
  38. this._titleNode.setContent(event.newVal);
  39. },
  40. syncUI: function () {
  41. // now that the DOM is created, syncUI sets it up
  42. // given the current state of our ATTRS
  43. this._afterTitleChange({
  44. newVal: this.get("title")
  45. });
  46. },
  47. destructor: function () {
  48. if (this.get("rendered")) {
  49. // bindUI was called, clean up events
  50. this._buttonClickHandler.detach();
  51. this._buttonClickHandler = null;
  52. // renderUI was called, clean up shortcuts
  53. this._titleNode = this._buttonNode = null;
  54. }
  55. }
  56. }, {
  57. // Public attributes that broadcast change events
  58. ATTRS: {
  59. title: {
  60. value: "No one gave me a title :("
  61. }
  62. },
  63. // Attributes whose default values can be scraped from HTML
  64. HTML_PARSER: {
  65. title: function (srcNode) {
  66. return srcNode.getAttribute("title");
  67. }
  68. }
  69. });
  70.  
  71. }, "3.3.0", {
  72. requires: [
  73. "base-build", // provides Y.Base.create
  74. "widget" // provides Y.Widget
  75. ],
  76. group: "nfl", // declares the nfl group (important for skins)
  77. skinnable: true // declares that your module is skinned
  78. });
Add Comment
Please, Sign In to add comment