window.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. // Make this available to both AMD and CJS environments
  7. define(function (require, exports, module) {
  8. // ReactJS
  9. const React = require("devtools/client/shared/vendor/react");
  10. // Reps
  11. const { isGrip, getURLDisplayString } = require("./rep-utils");
  12. // Shortcuts
  13. const DOM = React.DOM;
  14. /**
  15. * Renders a grip representing a window.
  16. */
  17. let Window = React.createClass({
  18. displayName: "Window",
  19. propTypes: {
  20. object: React.PropTypes.object.isRequired,
  21. },
  22. getTitle: function (grip) {
  23. if (this.props.objectLink) {
  24. return DOM.span({className: "objectBox"},
  25. this.props.objectLink({
  26. object: grip
  27. }, grip.class + " ")
  28. );
  29. }
  30. return "";
  31. },
  32. getLocation: function (grip) {
  33. return getURLDisplayString(grip.preview.url);
  34. },
  35. render: function () {
  36. let grip = this.props.object;
  37. return (
  38. DOM.span({className: "objectBox objectBox-Window"},
  39. this.getTitle(grip),
  40. DOM.span({className: "objectPropValue"},
  41. this.getLocation(grip)
  42. )
  43. )
  44. );
  45. },
  46. });
  47. // Registration
  48. function supportsObject(object, type) {
  49. if (!isGrip(object)) {
  50. return false;
  51. }
  52. return (object.preview && type == "Window");
  53. }
  54. // Exports from this module
  55. exports.Window = {
  56. rep: Window,
  57. supportsObject: supportsObject
  58. };
  59. });