PanelEnablerView.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2008 Apple Inc. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /**
  26. * @extends {WebInspector.View}
  27. * @constructor
  28. */
  29. WebInspector.PanelEnablerView = function(identifier, headingText, disclaimerText, buttonTitle)
  30. {
  31. WebInspector.View.call(this);
  32. this.registerRequiredCSS("panelEnablerView.css");
  33. this.element.addStyleClass("panel-enabler-view");
  34. this.element.addStyleClass(identifier);
  35. this.contentElement = document.createElement("div");
  36. this.contentElement.className = "panel-enabler-view-content";
  37. this.element.appendChild(this.contentElement);
  38. this.imageElement = document.createElement("img");
  39. this.contentElement.appendChild(this.imageElement);
  40. this.choicesForm = document.createElement("form");
  41. this.contentElement.appendChild(this.choicesForm);
  42. this.headerElement = document.createElement("h1");
  43. this.headerElement.textContent = headingText;
  44. this.choicesForm.appendChild(this.headerElement);
  45. var self = this;
  46. function enableOption(text, checked) {
  47. var label = document.createElement("label");
  48. var option = document.createElement("input");
  49. option.type = "radio";
  50. option.name = "enable-option";
  51. if (checked)
  52. option.checked = true;
  53. label.appendChild(option);
  54. label.appendChild(document.createTextNode(text));
  55. self.choicesForm.appendChild(label);
  56. return option;
  57. };
  58. this.enabledForSession = enableOption(WebInspector.UIString("Only enable for this session"), true);
  59. this.enabledAlways = enableOption(WebInspector.UIString("Always enable"), false);
  60. this.disclaimerElement = document.createElement("div");
  61. this.disclaimerElement.className = "panel-enabler-disclaimer";
  62. this.disclaimerElement.textContent = disclaimerText;
  63. this.choicesForm.appendChild(this.disclaimerElement);
  64. this.enableButton = document.createElement("button");
  65. this.enableButton.setAttribute("type", "button");
  66. this.enableButton.textContent = buttonTitle;
  67. this.enableButton.addEventListener("click", this._enableButtonCicked.bind(this), false);
  68. this.choicesForm.appendChild(this.enableButton);
  69. }
  70. WebInspector.PanelEnablerView.prototype = {
  71. _enableButtonCicked: function()
  72. {
  73. this.dispatchEventToListeners("enable clicked");
  74. },
  75. onResize: function()
  76. {
  77. this.imageElement.removeStyleClass("hidden");
  78. if (this.element.offsetWidth < (this.choicesForm.offsetWidth + this.imageElement.offsetWidth))
  79. this.imageElement.addStyleClass("hidden");
  80. },
  81. get alwaysEnabled() {
  82. return this.enabledAlways.checked;
  83. },
  84. __proto__: WebInspector.View.prototype
  85. }