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.9KB

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