Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp creating a JavaScript mixin in Tapestry5?
    primarykey
    data
    text
    <p>I am creating a mixin which renders a javascript file when a textfield gains focus.</p> <p>I am new to the idea of mixins in Tapestry, and I am unsure of where to place my original javascript file which i wish to run when the textfield gains focus.</p> <p>The following is an example of my code: The Java mixin class:</p> <pre><code>package asc.mixins; import org.apache.tapestry5.RenderSupport; import org.apache.tapestry5.annotations.AfterRender; import org.apache.tapestry5.annotations.Environmental; import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary; import org.apache.tapestry5.annotations.InjectContainer; import org.apache.tapestry5.corelib.base.AbstractTextField; @IncludeJavaScriptLibrary("js_dasher_mixin.js") public class DasherMixin { @Environmental private RenderSupport renderSupport; @InjectContainer private AbstractTextField field; @AfterRender void addScript() { this.renderSupport.addScript("new JSDasher('%s');", this.field.getClientId()); } } </code></pre> <p>The Javascript mixin file:</p> <pre><code>JSDasher = Class.create({ initialize: function(textField) { this.textField = $(textField); this.textField.observe('focus', this.onFocus.bindAsEventListener(this)); }, onFocus: function(event) { //call my javascript init() function } } </code></pre> <p>part of my javascript file I wish to run when the textfield gains focus:</p> <pre><code>var posX, posY; // Sets up our global variables and dispatches an init request to the server. function init() { posX=0; posY=0; canvas = document.getElementById("canvas"); canvasWidth = canvas.offsetWidth; canvasHeight = canvas.offsetHeight; if (canvas.getContext) { ctx = canvas.getContext("2d"); } canvas.onclick = canvasClicked; canvas.onmousemove = mouseMoved; canvasOffsetX = findPosX(canvas); canvasOffsetY = findPosY(canvas); sessID = -1; sendInitRQ(canvasWidth, canvasHeight); } </code></pre> <p>My javascript file is much larger than above, my question is where should I put my javascript code above?</p> <p>Should it all be contained in the mixin.js file? if so where exactly should it go?</p> <p>Thanks in advance for any help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload