Tooltips in Joomla containing HTML - javascript

I created a component using Component Creator for Joomla 3.X
The problem is that on the site the tooltips show html code. For example:
<strong>Title</strong><br/>Description
Instead, on the administrator they are displayed properly:
Title
Description
I was reviewing the documentation here and here, and it seems that it is possible to define the output format when calling the tooltip function but there are no calls inside the component to that function. The only call I see is JHtml::_('behavior.tooltip'); at the begining of the view file and don't know how to specify the output format.
The site is in this URL:
http://50.87.185.99/colombianadederecho_blank/index.php/administradores-ph/registrarse
Added:
It seems like the code is called when building the label for each field:
<div class="control-group">
<div class="control-label"><?php echo $this->form->getLabel('document'); ?></div>
<div class="controls"><?php echo $this->form->getInput('document'); ?></div>
</div>
And it is stored in the title attribute:
title="<strong>Title</strong><br />Description"
So, I think the problem is in the Javascript function, maybe using a .text() jQuery function instead of a .html().
Inspecting the source code I found this, but don't understand why it is not working properly:
window.addEvent('domready', function() {
$$('.hasTip').each(function(el) {
var title = el.get('title');
if (title) {
var parts = title.split('::', 2);
el.store('tip:title', parts[0]);
el.store('tip:text', parts[1]);
}
});
var JTooltips = new Tips($$('.hasTip'), {"maxTitleChars": 50,"fixed": false});
});
jQuery(document).ready(function() {
jQuery('.hasTooltip').tooltip({"html": true,"container": "body"});
});
Solution:
As #ilias found it was a problem between libraries. I had to disable the bootstrap call in the header using this plugin and call it from the end of the body:
<script src="/site/media/jui/js/bootstrap.min.js" type="text/javascript"></script>

I don't know the code that Component Creator produces, however I assume that the tooltips are like in the administrator views. If this is the case you should check for something like this:
<button type="submit" class="btn hasTooltip" title="<?php echo JHtml::tooltipText('JSEARCH_FILTER_SUBMIT'); ?>"><i class="icon-search"></i></button>
and enclose the contents of JHtml::tootlipText() in strip_tags().
Otherwise try to find the line <strong>Title</strong><br/>Description where the tags are shown and enclose it in strip_tags(). For example you might have something that looks like:
echo $this->escape($item->description);
that should be turned into:
echo $this->escape(strip_tags($item->description));

Related

Scraping text generated by script with PHP Simple HTML DOM Parser

I am trying to get the following text "Hug­gies Pure Baby Wipes 4 x 64 per pack" shown in the code below.
<div class="offerList-item-description-title">
<div id="result-title-5" class="offerList-item-description-title">
<script type="text/javascript">
document.write(getContents('wF8UD9Jj8:6D !FC6 q23J (:A6D c I ec A6C A24\<'));
</script>Hug­gies Pure Baby Wipes 4 x 64 per pack
</div>
</div>
I have tried using code such as:
foreach($element -> find('.offerList-item-description-title') as $title)
{
foreach($element -> find('text') as $text){
echo $text;
}
}
But just get returned an empty string, any suggestions?
Thanks.
If you are aware your HTML returned by your scraper does not contain Javascript rendered code, like in your case text is generated by javascript that's why you are getting empty response. What you need is a headless browser like PhantomJS you can use PHP wrapper of PhantomJS http://jonnnnyw.github.io/php-phantomjs/.
This will solve your problem. It has following features:
Load webpages through the PhantomJS headless browser
View detailed response data including page content, headers, status
code etc.
Handle redirects
View javascript console errors
Hope this helps.
I'm not sure what code your using in your example (and I suspect the getContents function result gets in the way of your method for retrieving the text) but if you wrap the text you're after in a <span> like so:
<div class="offerList-item-description">
<div id="result-title-5" class="offerList-item-description-title">
<script type="text/javascript">
document.write(getContents('wF8UD9Jj8:6D !FC6 q23J (:A6D c I ec A6C A24\<'));
</script><span>Hug­gies Pure Baby Wipes 4 x 64 per pack</span>
</div>
</div>
you can retrieve it using javascript:
<script>
var $title = document.getElementsByClassName("offerList-item-description-title");
for (var i = 0; i < $title.length; i++) {
var span = $title[i].getElementsByTagName("span");
var $text = span[0].innerText || span[0].textContent;
//echo $text;
console.log("==> " + $text);
}
</script>

How to handle load events and append in jquery

Hi I have a problem while using set interval function with .load events and append please explain what I did mistake in my code please give a solution
HTML
<div id="user2<?php echo $d['qid'] ;?>">
Comments Loads Here
Jquery code
setInterval(function(){
$("#user2").load( "test2.php,#user2");
},1000);
qid means Query id I have multiple(qid) queries in my site How to add append
please give a solution I am new in jquery Thanks in advance
Id of div is dynamic, as "qid" is appended to it.
<div id="user2<?php echo $d['qid'] ;?>">
In above code, if "$d['qid']" is 101, then generated html will be as given below.
<div id="user2101">
Hence, your javascript must include dynamic id using "" syntax. Also, you should be using space instead of comma in load event (http://api.jquery.com/load/#loading-page-fragments). You should be passing "qid" to "test2.php" page as query string to get comments related to "qid".
setInterval(function(){
$("#user2<?php echo $d['qid'] ;?>").load( "test2.php #user2");
},1000);
First, as qid is the query id. Having the following code with qid 2 will yield
<div id="user22">
Is this really the div you really want? If you want user2 it should be:
<div id="user<?php echo $d['qid'] ;?>">
Second, you need to pass a valid path to your page you want to load. Are you sure test2.php,#user2 is the correct path?

Javascript / Php : set textarea value

I have the following script, which returns 2 values from my database.
$(document).ready(function() {
<?
$link=new mysqli($serveur,$login,$pass,$base);
mysqli_set_charset($link, "utf8");
$r=mysqli_query($link, "select sujet,corps from mail where type='Création_rationnaire'");
while($row = mysqli_fetch_array($r)) {
?>
document.getElementById("sujet").value="<? echo $row[sujet];?>";
document.getElementById("te").value="<? echo $row[corps];?>";
<? }mysqli_close($link); ?>
});
Here are my 2 forms, one is a classic Input, the other is a textarea.
<input id='sujet' class="form-field">
<textarea id="te" class="textarea" rows="9" cols="70"></textarea>
The problem is : my SQL request works in MySQL, but when "corps" is echoed as above, nothing appears in the Inputs, like the script was crashing... Only "sujet" can be echoed successfully. So... why, just why ? Thanks in advance for whoever helps me.
EDIT : all I can echo in the "te" textbox is a single string like this : echo 'something';... but nothing else works...
Try this
document.getElementById("sujet").value="<? echo $row['sujet'];?>";
document.getElementById("te").text="<? echo $row['corps'];?>";
or if you use jquery
var message = <?php echo $row['corps']; ?>;
$("#te").val(message);
Textarea does not have a value but it does have text.
in an input box you would have <input type="text" value="example" /> and in a text area the value is inside the element like so
<textarea>example</textarea>
A other way is to use innerHtml (javascript) or html (jquery) .
But note that html tags will be display with one of these options
document.getElementById("te").innerHTML="<? echo $row['corps'];?>";
<textarea> doesn't have value property. Since you are using jQuery to bind document ready, you can use jQuery to set the value.
$("#sujet").val("<? echo $row[sujet];?>");
$("#te").html("<? echo $row[corps];?>");
What is the value of $row[corps]? Is it empty string? Does it contain double quote, or newline characters? If it contains any of them, it will break your javascript source code. What does javascript source code look like when you check source code inside the browser?
It works by inserting the values directly into the plain html forms. I usually use this javascript function because I have tons of forms to fill in my program, and it never failed until now... So my function above was good, but we still don't know why it failed in this particular case...
Problem solved anyways... thanks to everyone.

Using AngularJS code in template property of kendo window

I am using kendo window with AngularJS in the following way.
HTML Code
<div kendo-window="showProspectDetailWindow" k-title="'Prospect Detail window'"
k-width="" k-height="" k-visible="false"
k-content="{template:confirmationWindowTemplate}"
k-on-open="" k-on-close=""></div>
JavaScript Code
$scope.confirmationWindowTemplate = 'Are you sure you want to delete?<br />This data will not be recoverable, do you want to continue ?<br /><div class="pull-right"><button class="k-primary" ng-click = "yesButton()">Yes</button><button class="k-button" ng-click="noButton()"> No</button></div>';
I have created a model in the script in the following way
$scope.createProspectDetailModel = function(data)
{
$scope.prospectDetail.AccountId = data.AccountId;
$scope.prospectDetail.BusinessType = data.BusinessType;
$scope.prospectDetail.FirstName= data.FirstName;
}
The above code works. With the help of debugger I can verify that the values from the data field are going into each of the $scope.prospectDetail value. However, when I change my template into
$scope.confirmationWindowTemplate = 'Are you sure you want to delete {{prospectdetail.FirstName}}'
It doesn't work. I also tried
$scope.confirmationWindowTemplate = 'Are you sure you want to delete {{#= prospectdetail.FirstName #}}'
but it doesn't work as well. I have referred this link on SO but didn't help. I have searched a lot but still cannot find the solution to this. Any help would be appreciated.
Ok. I found the answer myself. I changed the HTML Code . Removed the k-content
<div kendo-window="confirmationWindow" k-title="'Confirmation window'"
k-width="" k-height="" k-visible="false"
k-on-open="" k-on-close=""></div>
and assigned it in the script
$scope.confirmationWindow.content('Are you sure you want to delete'+ $scope.prospectDetail.FirstName '?<br />

Magento :: Translate text from javascript files

Magento uses a system for translating text in the template files using:
$this->__('text to be translated.');
or
Mage::helper('modulename')->__('text to be translated.');.
This works quite well.
But when I add text to a javascript file I can't use these two methods.
Is there a way I could do a similar thing with the translations for javascript files?
You can do it in a template file yourfile.phtml. The JavaScript js/mage/translate.js file must be included in your HTML header (Magento does it by default).
<script type="text/javascript">
Translator.add('You should take care of this confirmation message!','<?php echo Mage::helper('yourmodule')->__('You should take care of this confirmation message!')?>');
</script>
Since Magento 1.7, you can add a file jstranslator.xml into your module under the etc/ folder and set the following string like that:
<jstranslator>
<!-- validation.js -->
<validate-no-html-tags translate="message" module="core">
<message>HTML tags are not allowed</message>
</validate-no-html-tags>
<validate-select translate="message" module="core">
<message>Please select an option.</message>
</validate-select>
</jstranslator>
Then translate the string as you do it for PHP thanks to the CSV file. This will add the translation to the JavaScript code like the following var Translator = new Translate(...).
Just use the following method in your scripts:
Translator.translate('Some phrase');
I just made the simplest way:
let sometext = '<?php echo $this->__('text to be translated.'); ?>' + someVarData;
This is the correct way for translating JavaScript strings withing .phtml file
Translator.add({"To be translated":"<?php echo $this->_('To be translated'); ?>"});
Use this is in js file:
Translator.translate('Some phrase');
But to make it work you should define this translation in phtml:
Translator.add('Some phrase', "<?php echo $this->__('Some phrase'); ?>");

Categories

Resources