How to display multiple links in a modal box in perl? - html

I am trying to display multiple links in a single modal box on onclick function like this
$cgi->img({ -src =>'/images/question.png',
-width=>10,
-border=>0,
-height=>10,
-alt=>'Redirect Link',
-onClick=>"image_click()"
}
),$cgi->div({-id="modal1",-class=>"modal"},$cgi->div({-class=>"modal2"},$cgi->span({-class=>"close",-onclick=>span_click()"},'×'),$cgi->p({},$links),),)
It's working fine when I want to display a single link but if I want to display multiple links in the same box.I wasn't able to get it.Instead I am getting the text of it.
My links looks something like this
my $links="'select a link',\$cgi->a({-href=>somelink},'LINK1'),\$cgi->a({-href=>somelink},'LINK2');
What am I doing wrong?

In this line:
my $links="'select a link',\$cgi->a({-href=>somelink},'LINK1'),\$cgi->a({-href=>somelink},'LINK2');
$cgi->a(...) is a method call, you have it in a double quoted string, but you can't interpolate method calls in a double quoted string.
Try something like this instead:
my #links = 'select a link', $cgi->a({-href=>somelink},'LINK1'), ...
Which creates an array of things rather than trying to put all the things in a string. Then change
$cgi->p({}, $links)
to:
$cgi->p({}, #links)
I haven't tested this - sorry.
Just because you're using CGI doesn't mean you have to use the CGI methods for generating HTML. I would strongly recommend looking at using a templating module like Template::Toolkit, or a framework like Mojolicious which can be run from CGI and includes a templating system (and has next to no dependencies).

Related

JSON object inside data-attribute without using the quotes (for the Slick Slider data-slick attribute)

I'm working on a website where I want to add the settings of my Slick Slider trough the data-attribute. This is possible with the 'data-slick' attribute. The format for this looks like this: data-slick='{"slidesToShow": 4, "slidesToScroll": 4}'.
In my WordPress CMS I'm using the plugin 'Data Attributes' to add data attributes to a Gutenberg Block. Trough this plugin all double and single quotes are converted to and therefor changes on the frontend to data-slick="{"slidesToShow": 4, "slidesToScroll": 4}"
This is not working. The Slick Slider doesn't use these settings.
Is there another way to add a JSON object into a data-attribute so it will work with the Slick Slider?
Thanks already for your help!
Kind Regards,
Nick
I think storing a JSON value in HTML is a bad idea. There are too many conditions which you have to take into consideration - backend returning page, WEB server encoding (it can add a custom encoding header), and browser compatibility. For this task, I'd prefer 2 ways: bitwise mask or simple function-for example, define a few data attributes -data-s1, data-s2, data-sn. In the JS code, add an array [ data-s1, data-s2, data-sn]. And finally, add a loop with an in-condition (if data.contains(element of array) - read and then parse the data inside of the attribute). I never worked with wordpress but for JS it is a easy task. If you need example write comment below. I can update my answer

Mediawiki extension used in a model with parameters

I'm using Mediawiki 1.18.1 and the anyweb extension. All is working well.
I'm trying to replace a chunk of several pages by a model (protected against edition)
The chunk I'm replacing use an extension (anyweb) and looks like:
<anyweb mywidth="100%" myheight="170">http://barbules.fr/warGAE/RASP/rasp.php?lat=50.028055555555554&lon=1.3005555555555557&good=NO,</anyweb>
I'm trying to replace it by a model like this:
{{Meteo|lat=50.028055555555554|lon=1.3005555555555557|good=SSO,}}
where the page Model:Meteo contains, for example:
<anyweb mywidth="100%" myheight="170">http://barbules.fr/warGAE/RASP/rasp.php?lat={{{lat|0.0}}}&lon={{{lon|0.0}}}&good=NO,</anyweb>
but the lat and lon variables are not evaluated by the model before passing to the anyweb extension; so the extension get as lat value {{{lat|0.0}}} in place of 50.028055555555554
Is it possible to use parameters of a model as part of an extension? How?
Extension tags contents are processed as-is (the parser can't know whether {{}} has special meaning in a tag). Use the #tag magic function to turn the tag into a template (sort of):
{{#tag|anyweb|<anyweb mywidth="100%" myheight="170">http://barbules.fr/warGAE/RASP/rasp.php?lat={{{lat|0.0}}}&lon={{{lon|0.0}}}&good=NO,|mywidth=100%|myheight=170}}

Using Jython to print html title?

In jython, is there a way to create a function that takes in a url (html) as a parameter, and returns the title of the url (whatever's in between the <title> and </title>)?
Of course it is!
At first download page you want to analyse. You can do it with urllib2 module. Read its documentation and at the bottom you will find examples of how to read page content.
When you have page content you must locate title in it. You can do it in many ways. There are modules for parsing HTML but for such simple task you can use regular expression (module re) or even string functions (find() method).
Be aware that HTML tags are case sensitive, so if you are going to use find() method to locate start and end of the title you may also need lower() method and copy of original page.

Upload Image not using erb (form) rails

I was wondering if there is a way to upload images in rails 4 not using erb. I have my html code in quotations in my model (so that i can use it as a default for when creating a page). SO I cant put erb in the quotes, cuz if i do it'll come out as the erb code and not the actual view. (i.e. the upload image form. itll come out as the actual f.image_tag instead of the actual upload button).
So I am just seeing if there another way i could implement image uploading into the quotations that wont require erb. But, uses Rails 4.
If you have plain HTML code inside the string, and just want it to be displayed, you need to call .html_safe in your view, like:
'<div id="foo">bar</div>'.html_safe()
Note that normally is a bad practice: that doesn't mean it is always bad, but it means that it is always an attention point to make sure it is the best way to do it.
If you want to do image upload without using form.image_tag, you can just put that in your view and see the generated code (Ctrl+U in Chrome), that, in this case, will be something like:
<input type="file" id="something" />
And add that to the string. Probably some finer validation and options are added too via JS, that would be a pain to add this way - one way to be to add a script tag to the html with the code.
If, however, your string already contains code like this, and you are asking way it is not working, then you need to add an eval to the caller, e.g.:
eval('form.image_tag :image')
Not that this is an even worse smell, and it should be avoided at all costs.
Maybe it would be better to add some flags in your section.rb model, and then use that in a helper or in the view render the html; for example, a has_upload? field, and then you can do something like this:
if #section.has_upload?
form.image_tag :imagem
end

Getting started styling JSON search results from DocumentCloud

I'm looking to build a system that styles the search results from DocumentCloud (and allows me to link to a given document).
I know I can query DocumentCloud and return JSON results using a search string like this:
https://www.documentcloud.org/api/search.json?q=obama
I don't know how to:
Grab the output of the search and put it on my own page
Style the data once I have it on my page
I'd just like to know how to get started with this, I'm experienced with HTML and CSS but I've never worked with JSON before.
There's more info here but I just don't know where to get started: https://www.documentcloud.org/help/api
It sounds like you're not so familiar with JavaScript, correct? JSON stands for JavaScript Ojbect Notation, so to work with it, you'll have to dive in a bit. I strongly recommend looking into using a JavaScript framework/library, namely jQuery to handle the heavy lifting. (There are other worthy libraries, but jQuery is by far the most popular, and is very friendly, using CSS-like selectors to manipulate the document object model).
check this jQuery tutorial: How jQuery Works
Here's a primer on using jQuery's jsonp to fetch remote rsults and using them in a page: http://www.ibm.com/developerworks/library/wa-aj-jsonp1/
You might end up with code in a javascript file, or a script tag (following a link to the jQuery library) that looks like this:
$(document).ready(function () {
$.getJSON('https://www.documentcloud.org/api/search.json?q=obama&callback=?', null, function (results) {
// this would append whatever the json returns for 'total'
// inside an element on your page with an id of 'resultsCount':
$('#restulsCount').append(data.total);
});
});
As a result, extra text & markup can be added to elements you already have on your page in whatever form/position you need it, and regular CSS rules from any style block or CSS file linked on your page will apply to them.
Good luck.