stylesheet.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 CSSStyleSheet
  16. */
  17. let StyleSheet = React.createClass({
  18. displayName: "object",
  19. propTypes: {
  20. object: React.PropTypes.object.isRequired,
  21. },
  22. getTitle: function (grip) {
  23. let title = "StyleSheet ";
  24. if (this.props.objectLink) {
  25. return DOM.span({className: "objectBox"},
  26. this.props.objectLink({
  27. object: grip
  28. }, title)
  29. );
  30. }
  31. return title;
  32. },
  33. getLocation: function (grip) {
  34. // Embedded stylesheets don't have URL and so, no preview.
  35. let url = grip.preview ? grip.preview.url : "";
  36. return url ? getURLDisplayString(url) : "";
  37. },
  38. render: function () {
  39. let grip = this.props.object;
  40. return (
  41. DOM.span({className: "objectBox objectBox-object"},
  42. this.getTitle(grip),
  43. DOM.span({className: "objectPropValue"},
  44. this.getLocation(grip)
  45. )
  46. )
  47. );
  48. },
  49. });
  50. // Registration
  51. function supportsObject(object, type) {
  52. if (!isGrip(object)) {
  53. return false;
  54. }
  55. return (type == "CSSStyleSheet");
  56. }
  57. // Exports from this module
  58. exports.StyleSheet = {
  59. rep: StyleSheet,
  60. supportsObject: supportsObject
  61. };
  62. });