combine ex:content and Javascript

170 views
Skip to first unread message

Andrea Borruso

unread,
Apr 30, 2015, 12:52:00 PM4/30/15
to simile-...@googlegroups.com
Hi,
I need to combine ex:content and Javascript.

Something like
<a ex:href-content=".URL" onclick="myfunction(ex:content='.URL'); return false;">my text</a>

But I obtain something wrong:
<a onclick="myfunction(ex:content='.URL')" href="http://myurl.com">my text</a>

And not:

<a href="http://myurl.com" onclick="myfunction('http://myurl.com'); return false;">my text</a>


What's wrong in my code?


Thank you very much

Charles

unread,
Apr 30, 2015, 5:35:35 PM4/30/15
to simile-...@googlegroups.com

try ex:onclick instead of just onclick
that's what worked for me. fyi I am using v2.2.
best of luck.
Charles

Andrea Borruso

unread,
May 2, 2015, 5:22:53 AM5/2/15
to simile-...@googlegroups.com
Hi Charles,
thank you.


On Thursday, 30 April 2015 23:35:35 UTC+2, Charles wrote:
try ex:onclick instead of just onclick
that's what worked for me. fyi I am using v2.2.

I'm using exhibit 3 and it seems to work. I have set:

<a ex:href-content=".URL" ex:onclick="myfunction(ex:content='.URL')">mytest</a>

 And I obtain only:

<a href="http://someurl.com">mytest</a>

Without any onclick function :(

Charles

unread,
May 2, 2015, 12:21:36 PM5/2/15
to simile-...@googlegroups.com
perhaps with Exhibit 3 it would work better using the updated syntax data-ex-onclick rather than ex:onclick ?

Andrea Borruso

unread,
May 4, 2015, 5:39:03 AM5/4/15
to simile-...@googlegroups.com
Hi all,
thank you, I made a few steps forward.

I have changed all the syntax from simile exhibit 2 to 3. But I'm still missing something.

I have applied my code to this demo website http://petrusino.opendatasicilia.it/index_test.html

In the cells of the column I have highlighted in the below image I have inserted this kind of code:

<td><a data-ex-href-content=".URL" data-ex-onclick-content=".URL">my text</a></td>

And I obtain:

<td><a href="http://samplesite.com" onclick="http://samplesite.com">my text</a></td>

I know that it's the right result. But I would like to obtain something like:

<td><a href="http://samplesite.com" onclick="myfunction('http://samplesite.com');">my text</a></td>

And I do not know how to write the right code.

Thank you




Luis Miguel Morillas

unread,
May 4, 2015, 6:09:23 AM5/4/15
to simile-...@googlegroups.com, abor...@gmail.com
<td><a data-ex-href-content=".URL"
data-ex-onclick-content="myfunction">my text</a></td>

or

<td><a data-ex-href-content=".URL" class="myfunction" >my text</a></td>

and set the onclick event at your js section


Saludos,

-- luismiguel (@lmorillas)
> --
> You received this message because you are subscribed to the Google Groups
> "SIMILE Widgets" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to simile-widget...@googlegroups.com.
> To post to this group, send email to simile-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/simile-widgets.
> For more options, visit https://groups.google.com/d/optout.

Andrea Borruso

unread,
May 4, 2015, 9:10:33 AM5/4/15
to simile-...@googlegroups.com, abor...@gmail.com
Hi Luis


On Monday, 4 May 2015 12:09:23 UTC+2, Luis Miguel Morillas wrote:
<td><a data-ex-href-content=".URL"
data-ex-onclick-content="myfunction">my text</a></td> 

I have inserted this and I have "No such variable called myfunction". Probably I must write some javascript code, but I have no idea what kind of.

Thank you
 

Luis Miguel Morillas

unread,
May 4, 2015, 12:19:56 PM5/4/15
to simile-...@googlegroups.com
What do you want the onclick event do? You must program this action
with a js function.


Saludos,

-- luismiguel (@lmorillas)

Andrea Borruso

unread,
May 4, 2015, 4:24:47 PM5/4/15
to simile-...@googlegroups.com
Hi Luis,

On 4 May 2015 at 18:19, Luis Miguel Morillas <mori...@gmail.com> wrote:
What do you want the onclick event do? You must program this action
with a js function.

ok, thank you. 

But it's not possible to use simile exhibit to write content inside a function that is inside an HTML tag?

My goal is simple. Imagine I have the function openURL and something like Start from something like <td><a href="./test.html" onclick="openURL('http://www.mysite.com');" >my text</a></td>

I have a list of arguments inside an exhibit db (a list of URL), and use a TabularView to create dinamically this HTML code. I'm looking for something like
<td><a href="./test.html" onclick="openURL(data-ex-content:".URL");" >my text</a></td> and produce something like

<tr><td><a href="./test.html" onclick="openURL('http://www.mysite1.com');" >my text</a></td></tr>
<tr><td><a href="./test.html" onclick="openURL('http://www.mysite2.com');" >my text</a></td></tr>
<tr><td><a href="./test.html" onclick="openURL('http://www.mysite3.com');" >my text</a></td></tr>
<tr><td><a href="./test.html" onclick="openURL('http://www.mysite4.com');" >my text</a></td></tr>
...

Then I have my function openURL, but I do not know how to use exhibit to fill dynamically its argument.

Thank you

Luis Miguel Morillas

unread,
May 4, 2015, 5:13:21 PM5/4/15
to simile-...@googlegroups.com
<script>
$(document).bind("dataload.exhibit", function() {
$("a.myfunction").click(function(event) {
event.preventDefault();

});
});
</script>
Saludos,

-- luismiguel (@lmorillas)

Luis Miguel Morillas

unread,
May 4, 2015, 5:17:04 PM5/4/15
to simile-...@googlegroups.com
Sorry, I sent last email incomplete:

<script>
$(document).bind("dataload.exhibit", function() {
$("a.myfunction").click(function(event) {
event.preventDefault();
<!-- rest of your function -->
});
});
</script>




<a data-ex-href-content=".URL" class="myfunction">mytest</a>


Saludos,

-- luismiguel (@lmorillas)

Andrea Borruso

unread,
May 5, 2015, 8:39:04 AM5/5/15
to simile-...@googlegroups.com
Hi Luis,
you are very kind and I feel myself stupid :)

On Monday, 4 May 2015 23:17:04 UTC+2, Luis Miguel Morillas wrote:
Sorry, I sent last email incomplete:

 <script>
    $(document).bind("dataload.exhibit", function() {
        $("a.myfunction").click(function(event) {
            event.preventDefault();
        <!-- rest of your function -->
        });
    });
    </script>


<a data-ex-href-content=".URL"  class="myfunction">mytest</a>

I have modified my sample app, and written a stupid code that writes "ciao" on the console on click on my table cells. You can view the result also in this video: http://youtu.be/RBrPmLmjd2k?hd=1 

My question is always the same: what exhibit code I must write to read in the console not "ciao", the value of a particolar field for that record? 

I think something like
    <script>
    $(document).bind("dataload.exhibit", function() {
        $("a.myfunction").click(function(event) {
            event.preventDefault();
            console.log(data-ex-content=".MyField");
        });
    });
    </script>

But it does not work.

Thank you again

Luis Miguel Morillas

unread,
May 5, 2015, 11:25:12 AM5/5/15
to simile-...@googlegroups.com
Hahaha, sure no!

What kind of field? An html attribute or an exhibit/json field? I
understood you wanted to process the href of the anchor.

If you want to show an html attribute for this anchor, use

--> alert(this.href);

Is it want you want?

I you want to use other field, you should extract it and hide with
css, and then use it on your function. If you give us a more precise
explanation of what you want to output, it will be more easy to help.




Saludos,

-- luismiguel (@lmorillas)

andy

unread,
May 5, 2015, 12:31:16 PM5/5/15
to simile-...@googlegroups.com
Hi Luis,
once again thank you.

On 5 May 2015 at 17:24, Luis Miguel Morillas <mori...@gmail.com> wrote:
What kind of field? An html attribute or an exhibit/json field? I
understood you wanted to process the href of the anchor.

If you want to show an html attribute for this anchor, use

-->  alert(this.href);

Is it want you want?

I you want to use other field, you should extract it and hide with
css, and then use it on your function. If you give us a more precise
explanation of what you want to output, it will be more easy to help.

I start from my first email. I would like to use data-ex-content values as arguments of a function of mine.
Something like

<a data-ex-href-content=".URL" onclick="myfunction(data-ex-content='.MyField')">my text</a>

This <a> tag will be the content of a cell of a column of a TabularView, and the the output will be something like:
<table>
<tr><td><a href="http://1RecordUrl.com" onclick="myfunction('1RecordArgument');">my text</a>
</td></tr>
<tr><td><a href="http://2RecordUrl.com" onclick="myfunction('2RecordArgument');">my text</a></td></tr>
<tr><td><a href="http://3RecordUrl.com" onclick="myfunction('3RecordArgument');">my text</a></td></tr>
</table>

Thank you



--
Andrea Borruso
website: http://blog.spaziogis.it
GEO+ geomatica in Italia http://bit.ly/GEOplus 
38° 7' 48" N, 13° 21' 9" E, EPSG:4326
--

"cercare e saper riconoscere chi e cosa,
 in mezzo all’inferno, non è inferno, 
e farlo durare, e dargli spazio"

Italo Calvino

andy

unread,
May 5, 2015, 5:31:14 PM5/5/15
to simile-...@googlegroups.com
Hi Luis,

On 4 May 2015 at 18:19, Luis Miguel Morillas <mori...@gmail.com> wrote:
What do you want the onclick event do? You must program this action
with a js function.

ok, thank you. 

But it's not possible to use simile exhibit to write content inside a function that is inside an HTML tag?

My goal is simple. Imagine I have the function openURL and something like Start from something like <td><a href="./test.html" onclick="openURL('http://www.mysite.com');" >my text</a></td>

I have a list of arguments inside an exhibit db (a list of URL), and use a TabularView to create dinamically this HTML code. I'm looking for something like
<td><a href="./test.html" onclick="openURL(data-ex-content:".URL");" >my text</a></td> and produce something like

<tr><td><a href="./test.html" onclick="openURL('http://www.mysite1.com');" >my text</a></td></tr>
<tr><td><a href="./test.html" onclick="openURL('http://www.mysite2.com');" >my text</a></td></tr>
<tr><td><a href="./test.html" onclick="openURL('http://www.mysite3.com');" >my text</a></td></tr>
<tr><td><a href="./test.html" onclick="openURL('http://www.mysite4.com');" >my text</a></td></tr>
...

Then I have my function openURL, but I do not know how to use exhibit to fill dynamically its argument.

Luis Miguel Morillas

unread,
May 5, 2015, 6:07:56 PM5/5/15
to simile-...@googlegroups.com
And the link you need for each term is at the .url column of you spreadsheet?


Saludos,

-- luismiguel (@lmorillas)

andy

unread,
May 5, 2015, 6:21:25 PM5/5/15
to simile-...@googlegroups.com

Luis yes, but not nessarely the .url column. I prefer to understand a solution for a generic column .examplefield, and use its cell values as argument of a function inside a <a> tag.

Thank you


You received this message because you are subscribed to a topic in the Google Groups "SIMILE Widgets" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simile-widgets/fLtKmlmRIUo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simile-widget...@googlegroups.com.

Luis Miguel Morillas

unread,
May 5, 2015, 6:27:17 PM5/5/15
to simile-...@googlegroups.com
I think the easiest solution is to use


<td><a data-ex-href-content=".url" class="myfunction" >my text</a></td>

or

<td><a data-ex-href-content=".examplefied" class="myfunction" >my
text</a></td> as you say ...



and at the script zone:

<script>
$(document).bind("dataload.exhibit", function() {
$("a.myfunction").click(function(event) {
event.preventDefault();
console.log(this.url);
});
});
</script>




Saludos,

-- luismiguel (@lmorillas)


David Karger

unread,
May 5, 2015, 11:05:20 PM5/5/15
to simile-...@googlegroups.com
You may want to explore the use of the "subcontent" feature on exhibit attributes:
http://simile-widgets.org/wiki/How_to_create_dynamic_URLs_using_ex:*-subcontent

Andrea Borruso

unread,
May 6, 2015, 3:14:18 AM5/6/15
to simile-...@googlegroups.com, kar...@mit.edu
Hi David,
great!!!


On Wednesday, 6 May 2015 05:05:20 UTC+2, David Karger wrote:
You may want to explore the use of the "subcontent" feature on exhibit attributes:
http://simile-widgets.org/wiki/How_to_create_dynamic_URLs_using_ex:*-subcontent

It was exactly what I'm looking for, thank you very much. I was sure that there was something like that, but I could not find it. I have applied it in the first column, here http://petrusino.opendatasicilia.it/

I want to say thank you again to Luis that have read all my nasty email, he taught me many valuable things.
Thank you again David for this pearl.
Thank you to this community.

This pearl should be in the simile exhibit 3 documentation. Is there a way to contribute to it?


Best regards,

Andrea

David Karger

unread,
May 6, 2015, 9:31:52 AM5/6/15
to Andrea Borruso, simile-...@googlegroups.com
Exhibit documentation is really quite a mess at the moment; it's scattered over many places and not up to date.  I'd like to fix it but it's going to take a substantial effort, not piecemeal work.  If someone is interested in tackling that I'd love to talk to them about how to do it.

Andrea Borruso

unread,
May 6, 2015, 12:40:04 PM5/6/15
to simile-...@googlegroups.com, kar...@mit.edu, abor...@gmail.com
Hi David,


On Wednesday, 6 May 2015 15:31:52 UTC+2, David Karger wrote:
Exhibit documentation is really quite a mess at the moment; it's scattered over many places and not up to date.  I'd like to fix it but it's going to take a substantial effort, not piecemeal work.  If someone is interested in tackling that I'd love to talk to them about how to do it.

I'm interest to collaborate in update and build documentation. I think that using github as platform could be great.

Best regards 

Luis Miguel Morillas

unread,
May 6, 2015, 5:09:15 PM5/6/15
to simile-...@googlegroups.com
What's your idea about refactoring documentation? I think I can help
too. Not now but maybe this summer.
Saludos,

-- luismiguel (@lmorillas)

Contemplative

unread,
May 14, 2015, 9:28:12 PM5/14/15
to simile-...@googlegroups.com, abor...@gmail.com, kar...@mit.edu
I would be willing to work on documentation for exhibit as well.
Would need to know where existing docs are (the scattered parts).
I agree with Andrea that github would be a good place to start.
Let me know how I might help.

wjw

David Karger

unread,
May 14, 2015, 11:21:10 PM5/14/15
to Contemplative, simile-...@googlegroups.com, abor...@gmail.com
Thanks both for volunteering!  Once I finish grading I'll try to put together a plan of attack.

Contemplative

unread,
May 15, 2015, 1:55:28 PM5/15/15
to simile-...@googlegroups.com, kar...@mit.edu, abor...@gmail.com
I look forward to getting started on this.
Thanks
wjw

Геннадий Кондратьев

unread,
Oct 25, 2017, 7:46:32 AM10/25/17
to SIMILE Widgets
It doesn't work at all!

пятница, 1 мая 2015 г., 0:35:35 UTC+3 пользователь Charles написал:
Reply all
Reply to author
Forward
0 new messages