object-with-url.js 1.8 KB

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