Guest User

Untitled

a guest
Sep 14th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | None | 0 0
  1. /**
  2. * The accordion panel is a group of toggles
  3. * interconnected by
  4. */
  5. (function () {
  6. /**
  7. * a pull component which pulls
  8. * a certain area periodically
  9. */
  10. var _RT = myfaces._impl.core._Runtime;
  11.  
  12. _RT.extendClass("extras.apache.ImageButton", extras.apache.ComponentBase, {
  13.  
  14. _LANG: myfaces._impl._util._Lang,
  15.  
  16. _imageNormal: null,
  17. _imagePressed: null,
  18. _imageFocus: null,
  19. _label: null,
  20. _imageCommand: null,
  21. onClick: null,
  22. autoWidth: true,
  23.  
  24. constructor_:function(args) {
  25. this._callSuper("constructor", args);
  26. this._onMouseDown = this._LANG.hitch(this, this._onMouseDown);
  27. this._onMouseUp = this._LANG.hitch(this, this._onMouseUp);
  28. this._onClickCallback = this._LANG.hitch(this, this._onClickCallback);
  29. this._onKeyDown = this._LANG.hitch(this, this._onKeyDown);
  30. this._onKeyUp = this._LANG.hitch(this, this._onKeyUp);
  31. this._postInit = this._LANG.hitch(this, this._postInit);
  32. setTimeout(this._postInit, 0);
  33. },
  34.  
  35. _postInit:function() {
  36. this._callSuper("_postInit", arguments);
  37. this._imageNormal = this.rootNode.querySelector(".imageNormal");
  38. this._imagePressed = this.rootNode.querySelector(".imagePressed");
  39. this._imageFocus = this.rootNode.querySelector(".imageFocus");
  40.  
  41. this._label = this.rootNode.querySelector(".label");
  42. this._imageCommand = this.rootNode.querySelector(".imageCommand");
  43.  
  44. //now we fix the values
  45. if(!this._imagePressed.getAttribute("src") || this._imagePressed.getAttribute("src") == "") {
  46. this._imagePressed.setAttribute("src", this._imageNormal.getAttribute("src"));
  47. }
  48. if(!this._imageFocus.getAttribute("src") || this._imageFocus.getAttribute("src") == "") {
  49. this._imageFocus.setAttribute("src", this._imageNormal.getAttribute("src"));
  50. }
  51.  
  52. //now we apply the event handlers
  53. //click should make a short animation between the image changes
  54. //mousedown should apply the click styleclass
  55. //mouseup on a global scale should remove the image styleclass
  56. this.rootNode.addEventListener("mousedown", this._onMouseDown, false);
  57.  
  58. this.rootNode.addEventListener("keydown", this._onKeyDown, false);
  59. this.rootNode.addEventListener("keyup", this._onKeyUp, false);
  60.  
  61.  
  62. //this.rootNode.addEventListener("mouseup", this._onMouseUp, false);
  63.  
  64. //this.rootNode.addEventListener("click", this._onClick, false);
  65. this.rootNode.toDomNode().addEventListener('click', this._onClickCallback, false)
  66. //var _t = this;
  67. //this.rootNode.querySelectorAll("*").forEach(function(elem) {
  68. // if(!elem.hasClass("imageCommand")) {
  69. // elem.toDomNode().addEventListener('click', _t._onClickCallback, false);
  70. // }
  71. //});
  72. if(this.autoWidth) {
  73. var innerWidth = parseInt(this._imageNormal.offsetWidth()) +
  74. parseInt(this._label.offsetWidth())+
  75. Math.min(
  76. parseInt(this._imageNormal.offsetLeft()) * 3,
  77. parseInt(this._label.offsetLeft()) * 3);
  78. this.rootNode.setStyle("width",innerWidth+"px");
  79. }
  80.  
  81. },
  82.  
  83. _onClickCallback: function(evt) {
  84. var ret = (this.onClick) ? this.onClick(evt): true;
  85. var currentTime = (new Date()).getTime();
  86. //double click prevention
  87. evt.stopPropagation();
  88. if(extras.apache.ImageButton.__lastClick && (currentTime - extras.apache.ImageButton.__lastClick) < 500) {
  89. extras.apache.ImageButton.__lastClick = currentTime;
  90. return;
  91. }
  92. extras.apache.ImageButton.__lastClick = currentTime;
  93. if(!ret) return;
  94. //for strange kind of reasons we bubble a click up
  95. this._imageCommand.toDomNode().onclick();
  96.  
  97. },
  98.  
  99. _onMouseDown: function(evt) {
  100. this.rootNode.addClass("clicked");
  101. window.addEventListener("mouseup", this._onMouseUp, false);
  102. },
  103.  
  104. _onMouseUp: function(evt) {
  105. this.rootNode.removeClass("clicked");
  106. window.removeEventListener("mouseup", this._onMouseUp, false);
  107.  
  108. },
  109.  
  110. _onKeyDown: function(evt) {
  111.  
  112. var keyCode = evt.keyCode;
  113. if(evt.keyCode == this.KEY_ENTER) {
  114. this.rootNode.addClass("clicked");
  115. }
  116. },
  117.  
  118. _onKeyUp: function(evt) {
  119. var keyCode = evt.keyCode;
  120. if(evt.keyCode == this.KEY_ENTER) {
  121. this.rootNode.removeClass("clicked");
  122. this._onClickCallback(evt);
  123. }
  124. }
  125.  
  126. });
  127. })
  128. ();
Add Comment
Please, Sign In to add comment