Views for Mashups and Mashables : Built-in Presto Views : Template View : Use JavaScript in Template Code
Use JavaScript in Template Code
You can add JavaScript code directly to a custom view or template using the <script> tag. For example:
<div>
<div id="myMsg"></div>
<script>jQuery("myMsg").html("Welcome stranger!");</script>
</div>
You can also refer to external JavaScript libraries. External libraries must:
*Have a fully-qualified URL where the library is hosted. For example:
<div>
<script type="text/javascript"
scr="http://some.example.com/libraries/commonView.js"/>
...
</div>
Generally, you should use this option for external libraries hosted by third parties or libraries for your organization that are hosted outside of Presto. Hosting JavaScript libraries for your organization in the Presto or Presto Hub web applications is not recommended as this complicates deployment and upgrade migrations.
*Have been uploaded to Presto and use a Presto URL.
This option is recommended when JavaScript libraries cannot be hosted outside of Presto or these resources should be available for use in many custom views.
Note:  
External resources can only be uploaded to Presto by Presto administrators.
This example uses a JavaScript library that has been uploaded to Presto. The full path for this URL is defined when the resource is uploaded, but is generally in the form http:app-server:port/presto/files/library-name:
<div>
<script type="text/javascript"
scr="http://localhost:8080/presto/files/commonView.js"/>
...
</div>
Loading and Scope
Custom views become part of the user interface for apps which in turn are published and run inside of other web pages or mobile devices. Thus scripts are loaded and run within the body of another page. Typically, the DOM for the page is fully loaded.
Scripts should also use a unique namespace to ensure there are no naming conflicts with other code running within that page.
Events and Event Handlers
Custom views support all of the standard DOM events. Developers can also use jQuery functions to register event handlers or to define and fire custom events. For example:
...
<button id="event1">Trigger an event</button>
<script type="text/javascript">
jQuery("#event1").click(function(){
jQuery(this).parent().trigger("myEvent", {
eventdata: { type: 'button', time: (new.Date()).toString() }
}
);
});
</script>
...
Copyright © 2013-2015 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback