Is it possible to use html in Foundation's tooltips?
Yes. It supports html in the title attribute.
from foundation.tooltip.js:
create : function ($target) {
var $tip = $(this.settings.tip_template(this.selector($target), $('<div></div>').html($target.attr('title')).html())),
...
Breaking that down it creates a new element wrapped in a div and the contents of the title attribute are inserted into the div using the html() method which will convert any markup in the string to html elements.
The following code:
<img src="example.png"
class="general-infotip has-tip tip-top"
data-tooltip
title="<b>This is bold</b> This is not" />
Will result in a tool tip that looks like
This is bold This is not
In Foundation v6.3+, you can append the attribute data-allow-html="true" to the element to allow html in the tooltip.
For example:
<span data-tooltip data-allow-html="true" aria-haspopup="true"
class="has-tip" data-disable-hover="false" tabindex="1"
title="Fancy word for a <strong>beetle</strong>. <br><br><img src=https://pbs.twimg.com/profile_images/730481747679432704/uc08_dqy.jpg />">
Scarabaeus
</span>
Here it is working in jsfiddle.
For more information, check out the pull request.
Related
I am trying to implement jQuery with PrimeFaces and JSF components, but it's not working properly. When I tried to do the same with HTML tags it;s working properly.
Here is the code with HTML tags which works properly with jQuery:
<input type="checkbox" id="check2"></input>
<h:outputText value="Check the box, if your permanent address is as same as current address."></h:outputText>
<h:message for="checkbox" style="color:red" />
with
$("#check2").change(function() {
if ($("#check2").is(":checked")) {
$("#p2").hide();
} else {
$("#p2").show();
}
});
Here is the code with PrimeFaces/JSF which doesn't work properly with jQuery:
<p:selectManyCheckbox >
<f:selectItem itemLabel="1" value="one" id="rad" ></f:selectItem>
</p:selectManyCheckbox>
with
$("#rad").change(function() {
if ($("#rad:checked").val() == "one") {
$("#p2").hide();
} else {
$("#p2").show();
}
});
You should realize that jQuery works with the HTML DOM tree in the client side. jQuery doesn't work directly on JSF components as you've written in the JSF source code, but jQuery works directly with the HTML DOM tree which is generated by those JSF components. You need to open the page in webbrowser and rightclick and then View Source. You'll see that JSF prepends the ID of the generated HTML input elements with the IDs of all parent NamingContainer components (such as <h:form>, <h:dataTable>, etc) with : as default separator character. So for example
<h:form id="foo">
<p:selectManyCheckbox id="bar" />
...
will end up in generated HTML as
<form id="foo" name="foo">
<input type="checkbox" id="foo:bar" name="foo:bar" />
...
You need to select elements by exactly that ID instead. The : is however a special character in CSS identifiers representing a pseudo selector. To select an element with a : in the ID using CSS selectors in jQuery, you need to either escape it by backslash or to use the [id=...] attribute selector or just use the old getElementById():
var $element1 = $("#foo\\:bar");
// or
var $element2 = $("[id='foo:bar']");
// or
var $element3 = $(document.getElementById("foo:bar"));
If you see an autogenerated j_idXXX part in the ID where XXX represents an incremental number, then you must give the particular component a fixed ID, because the incremental number is dynamic and is subject to changes depending on component's physical position in the tree.
As an alternative, you can also just use a class name:
<x:someInputComponent styleClass="someClassName" />
which ends up in HTML as
<input type="..." class="someClassName" />
so that you can get it as
var $elements = $(".someClassName");
This allows for better abstraction and reusability. Surely those kind of elements are not unique. Only the main layout elements like header, menu, content and footer are really unique, but they are in turn usually not in a NamingContainer already.
As again another alternative, you could just pass the HTML DOM element itself into the function:
<x:someComponent onclick="someFunction(this)" />
function someFunction(element) {
var $element = $(element);
// ...
}
See also:
How can I know the id of a JSF component so I can use in Javascript
How to use JSF generated HTML element ID with colon ":" in CSS selectors?
By default, JSF generates unusable IDs, which are incompatible with the CSS part of web standards
Integrate JavaScript in JSF composite component, the clean way
You also can use the jQuery "Attribute Contains Selector" (here is the url http://api.jquery.com/attribute-contains-selector/)
For example If you have a
<p:spinner id="quantity" value="#{toBuyBean.quantityToAdd}" min="0"/>
and you want to do something on its object you can select it with
jQuery('input[id*="quantity"]')
and if you want to print its value you can do this
alert(jQuery('input[id*="quantity"]').val());
In order to know the real html tag of the element you can always look at the real html element (in this case spinner was translated into input) using firebug or ie developer tools or view source...
Daniel.
If you're using RichFaces you can check rich:jQuery comonent. It allows you to specify server side id for jQuery component. For example, you have component with specified server id, then you can apply any jQuery related stuff to in next way:
<rich:jQuery selector="#<server-side-component-id>" query="find('.some-child').removeProp('style')"/>
For more info, please check doumentation.
Hope it helps.
look this will help you when i select experience=Yes my dialoguebox which id is dlg3 is popup.and if value is No it will not open
i using simple_html_dom.php
how to get textarea value if the website has used bad tag.
the textarea tag already closed before </textarea> like input tag.
Textarea HTML like below:
<textarea name="xxx" id="xxx" />this is value</textarea>
When i use this function, i dont get anything
$textarea = $html->find("textarea[name=xxx]");
$contents = $textarea->innertext;
echo $contents;
how to get 'this is value' using simple_html_dom.php or other alternative?
Thank you
Well, my previous comment won't work in this case, I'll leave it for info though...
Another approach is to clean it up before parsing it with simple_html_dom using Tidy extension. But it seems not to be working here either...
A last approach I can think of, and if this is your only problematic case, is to use regex to get what you want:
Using <textarea.*?name="xxx".*?id="xxx".*?\/>([^<]+)<\/textarea> ==> RegEx DEMO
The output will be in group one of the resulting array $match. Check this working code:
$input = <<<_DATA_
<textarea name="xxx" id="xxx" />this is value</textarea>
_DATA_;
$pattern = '/<textarea.*?name="xxx".*?id="xxx".*?\/>([^<]+)<\/textarea>/';
preg_match($pattern, $input, $match);
var_dump($match)
Working DEMO
It is easy to get the value of a Teaxtarea in javascript:
<script type=text/javascript>
function getValueTextarea()
{
var vl=document.getElementById("tx").value;
alert(vl);
}
</script>
<body>
<textarea id="tx">Value Of Textarea</textarea>
<input id="button" value="Get Value" onclick="getValueTextarea()">
</body>
I have a grails render tag that renders a small chunk of HTML. Sometimes the HTMl needs to display some text, and sometimes some text and a link.
This chunk of code is working fine:
<g:render template='accountInfo' model="[
'accountStatus':subscription.status,
'subscription':subscription.plan.name,
'msg':g.message (code: 'stripe.plan.info', args:'${[periodStatus, endDate]}')]"/>
But I want to be able to pass in some HTML for the 'msg' variable in the model, like this to ouput some text and a link:
<g:render template='accountInfo' model="[
'accountStatus':profile.profileState,
'subscription':'None selected yet',
'msg':Your profile is currently inactive, select a plan now to publish your profile.]"/>
That code does not work. I've tried adding the link to a taglib, but I can't figure out how to pass the taglib to the 'msg' either:
<g:render template='accountInfo' model="[
'accountStatus':profile.profileState,
'subscription':'None selected yet',
'msg':<abc:showThatLink/>]"/>
I am open to suggestions on how best to achieve passing in text only, and text and a grails createLink closure along with some text for the link.
You have multiple options:
1 Use quotes:
<g:render template='accountInfo' model='${ [msg: "<a href='www.someurl.com'>.. </a>"]}' />
2 Use another variable:
<g:set var="myMsg>
<a href="www.someurl.com>...</a>
</g:set>`
<g:render template='accountInfo' model='[ 'msg': ${myMsg} ]'/>
3 Use the body content of <g:render />:
<g:render template="accountInfo" model="[ .. ]">
..
</g:render>
You can use to body() method inside the template (accountInfo) to render the body content. Some time ago I wrote a small blog post about this which gives some more details.
I am trying to bind jquery mobile horizantal radio buttons using knock out teplate binding.
The fielsset in template looks like
<fieldset data-role="controlgroup" data-bind="attr: {id:QuestionID+'_fld'},template: {name:'optionTemplate', foreach: OptionList}">
</fieldset>
and the option template looks like
<script type="text/x-jquery-tmpl" id="optionTemplate">
<input type="radio" data-bind="attr: { id:OptionID+'_radio',value:OptionID, name: QuestionID+'_rd'}, checked:$parent.OptionId" />
<label data-bind="text:OptionText, attr: {id:OptionID+'_optn', for : QuestionID+'_rd' }"> </lable>
</script>
I have tried
$('input[type=radio]').checkboxradio().trigger('create');
$('fieldset').controlgroup().trigger('create');
Here my problem is that the mobile css is not applying to the fiedset.
You must do this after the template has built your page or during the page initialization event, something like this:
$(document).on('pagebeforeshow', '#pageID', function(){
});
Page content can be enhanced ONLY when content is safely loaded into the DOM.
Second this do NOT mix refresh functions with trigger create. Either one or the other. Trigger create is used to enhance whole content, and it should NOT be used on single elements. No point in restyling whole page every time you add new content.
Basically you only want to use:
$('input[type=radio]').checkboxradio().checkboxradio('refresh');
or if first line throws an error:
$('input[type=radio]').checkboxradio();
and:
$('fieldset').controlgroup();
But I would advise you to only use this line after everything has been appended:
$('#contentID').trigger('create');
where #contentID is an id of your div data-role="content" object. Or in case you are not using content div, only data-role="page" div then use this:
$('#pageID').trigger('pagecreate');
where #pageID is an id of your page.
To find out more about marku enhancement of dynamically added content take a look at this answer.
I want to transform a div composed of image + text (for translation) in a submit button. Is it possible?
I managed to use the image as submit but the text is not a link and it gives a 'broken' feeling to the whole image + text
<div onclick="document.myform.submit()"></div>
Jquery usage.
$('div').click(function () {
$('form').submit();
});
You can do it in two ways.
You can use a button with type submit and use CSS to style it as a div
Add an onClick on the div, and submit the form on the click event.
For method 2 you can either do it through jQuery or without, With plain js
<script>
function submitOnClick(formName){
document.forms[formName].submit();
}
</script>
<form id="myForm" ...>
....
<div onclick="submitOnClick('myForm')>
...
</div>
...
</form>
Trevor's answer shows how to do it with jQuery.
In his example just replace the 'div' and 'form' with the ids of your div and form as this:
If ids of div and form are myDiv and myForm specify them as '#myDiv' and '#myForm', here # is used to specify the following string is an id of an element.