You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UsingAJavaScriptLibraryOrAStyleSheetInAnAddOn.asciidoc 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ---
  2. title: Using A JavaScript Library Or A Style Sheet In An Add On
  3. order: 40
  4. layout: page
  5. ---
  6. [[using-a-javascript-library-or-a-style-sheet-in-an-addon]]
  7. = Using a JavaScript library or a style sheet in an add-on
  8. Including style sheets or JavaScript files in your add-ons or as a part
  9. of your application can now be done by adding a `@StyleSheet` or
  10. `@JavaScript` annotation to a `Component` or `Extension` class. Each
  11. annotation takes a list of strings with URLs to the resources that
  12. should be loaded on the page before the framework initializes the
  13. client-side `Component` or `Extension`.
  14. The URLs can either be complete absolute urls (e.g. https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js) or
  15. relative URLs (e.g. _redbutton.css_). A relative URL is converted to a
  16. special URL that will download the file from the Java package where the
  17. defining class is located. This means that e.g.
  18. `@StyleSheet({"redbutton.css"})` on the class `com.example.RedButton` will
  19. cause the file `com/example/redbutton.css` on the classpath to be loaded
  20. in the browser. `@JavaScript` works in exactly the same way - see
  21. <<IntegratingAJavaScriptComponent#, Integrating a JavaScript component>>
  22. for a practical example.
  23. [source,java]
  24. ....
  25. @StyleSheet("redbutton.css")
  26. public class RedButton extends NativeButton {
  27. public RedButton(String caption) {
  28. super(caption);
  29. addStyleName("redButton");
  30. }
  31. }
  32. ....
  33. In this simple example, the `RedButton` component just adds a `redButton`
  34. style name to a normal `NativeButton`. _redbutton.css_ is located in the
  35. same folder as _RedButton.java_ and has this content:
  36. [source,css]
  37. ....
  38. .redButton {
  39. background-color: red;
  40. }
  41. ....
  42. This new mechanism makes it very easy to include style sheet or
  43. JavaScript files with add-ons and automatically load them in the browser
  44. when the add-on is used.