document.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 { span } = React.DOM;
  14. /**
  15. * Renders DOM document object.
  16. */
  17. let Document = React.createClass({
  18. displayName: "Document",
  19. propTypes: {
  20. object: React.PropTypes.object.isRequired
  21. },
  22. getLocation: function (grip) {
  23. let location = grip.preview.location;
  24. return location ? getURLDisplayString(location) : "";
  25. },
  26. getTitle: function (grip) {
  27. if (this.props.objectLink) {
  28. return span({className: "objectBox"},
  29. this.props.objectLink({
  30. object: grip
  31. }, grip.class + " ")
  32. );
  33. }
  34. return "";
  35. },
  36. getTooltip: function (doc) {
  37. return doc.location.href;
  38. },
  39. render: function () {
  40. let grip = this.props.object;
  41. return (
  42. span({className: "objectBox objectBox-object"},
  43. this.getTitle(grip),
  44. span({className: "objectPropValue"},
  45. this.getLocation(grip)
  46. )
  47. )
  48. );
  49. },
  50. });
  51. // Registration
  52. function supportsObject(object, type) {
  53. if (!isGrip(object)) {
  54. return false;
  55. }
  56. return (object.preview && type == "HTMLDocument");
  57. }
  58. // Exports from this module
  59. exports.Document = {
  60. rep: Document,
  61. supportsObject: supportsObject
  62. };
  63. });