Thank you for the suggestion. I tried it (fragments provided below) but the 
javascript function doesn't appear to be getting called. I must admit to 
being a javascript numbno but have been successful with other javascript 
tasks and following other javascript examples in the SWP pages I am working 
on.

Here is the javascript I am putting in the ui:headIncludes (I have also 
tried embedding it into the ui:prototype):

<ui:group>

    <link href="lib/nia/styles/nia.css" rel="stylesheet" type="text/css"/>

    <link href="lib/nia/styles/linkedmodels.min.css" rel="stylesheet" 
type="text/css"/>

    <script type="text/javascript">$('document').ready(function(){

    function storeCurrentResource(resource) {

        if (!supportsLocalStorage()) { alert("no local storage"); }

        localStorage["selected_data"] = resource;

        alert("yes");

        return true;

}

});</script>

</ui:group>

As you can see, the only purpose of this function is to save the resource 
into local storage. Saving content into local storage is working just fine 
for button clicks.

Here is the call in the ui:prototype:

<ui:setContext ui:queryGraph="{= ui:graphWithImports(nia:maybeConvertToURI(
?context)) }">

    <ui:group>

        <swa:FullScreenBorderLayout>

            <div class="ui-layout-center" ui:childIndex="3">

                <div class="tuiView" let:myClass="{= spl:object(?resource, 
rdf:type) }">

                    <h2>{= ui:label(?myClass) }</h2>

                    <h3>{= ui:label(?resource) }</h3>

                    <script ui:childIndex="1">storeCurrentResource('{= 
?resource }');</script>

                    <div class="lm_resource_summary" ui:childIndex="2">

                        <p>{= nia:getDescription(?resource) }</p>

                        <p class="lm-qname">QName = {= ui:encodeNode(
?resource) }</p>

                    </div>
                           ...

What follows is just standard SWP content. The page renders fine so there 
is nothing noteworthy in the SPARQL of page view content. Is this a valid 
way to call a javascript function in the body? I followed your example 
syntax and other examples we have.

Jack

On Wednesday, October 31, 2012 5:18:33 PM UTC-7, Holger Knublauch wrote:
>
> On 11/1/2012 3:46, Jack Hodges wrote: 
> > The SWP user guide says that the content in ui:headIncludes is copied 
> > into the <head> portion of the html when it is constructed. If I refer 
> > to one of the spin constraint variables (e.g. ?resource) in the 
> > javascript, will it be resolved properly in the page? -- 
>
> Hi Jack, 
>
> ui:headIncludes cannot access variables from the element instance, so 
> even if your SWP element takes arguments they will be unbound in the 
> ui:headIncludes. This is because the headIncludes are only inserted once 
> for a page, and many components in the same class hierarchy may share 
> the same headIncludes by inheritance. 
>
> Also note that in order to use SPARQL variables in JavaScript, they are 
> (of course) not evaluated client-side, but server side. So a typical 
> scenario is to have something like 
>
> <script> 
>      function myFunction(resource) { 
>          doSomething(resource); 
>      } 
> </script> 
>
> in your ui:headIncludes and then use 
>
> <script>myFunction('{= ?resource }')</script> 
>
> in the ui:prototype to call the static JavaScript code from the head. 
> This will hopefully address your scenario. If not please provide details. 
>
> HTH 
> Holger 
>
>
> > -- You received this message because you are subscribed to the Google 
> > Group "TopBraid Suite Users", the topics of which include Enterprise 
> > Vocabulary Network (EVN), TopBraid Composer, TopBraid Live, 
> > TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN. 
> > To post to this group, send email to 
> > [email protected] <javascript:> 
> > To unsubscribe from this group, send email to 
> > [email protected] <javascript:> 
> > For more options, visit this group at 
> > http://groups.google.com/group/topbraid-users?hl=en 
> > 
> > 
>
>

-- 
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary 
Network (EVN), TopBraid Composer, TopBraid Live,
TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en


Reply via email to