How to allow goog.html.sanitizer.HtmlSanitizer.Builder to permit the "placeholder" attribute - google-closure-compiler

I use goog.html.sanitizer.HtmlSanitizer.Builder to create safe HTML that I then dynamically insert into a dialog. I wanted to have an input field that uses the Html 5 "placeholder" attribute.
I tried
.alsoAllowTagsPrivateDoNotAccessOrElse ([ "placeholder"])
and got an expected nasty compiler error!

I ended up adding the place holder attribute to the closure-library attribute white list javascript code. The call to alsoAllowTagsPrivateDoNotAccessOrElse was removed and all worked well.

Related

Stop TinyMCE 4.1.9 from removing orphaned children tags

I am wanting to use ANY tag inside of TinyMCE without it being removed, but it's not working. My current input is:
<tr><td>[item-thumb]</td><td>[item-count]</td><td>[item-location]</td><td>[item-title]</td><td>[item-desc]</td><td>[low-estimate]</td></tr>
This is used to iterate through items and replace the short-codes with item data, and put that into a table. However, it always strips out the tr and td tags because it is not wrapped in a table tag.
I've tried:
valid_elements: "+*[*]",
valid_children: "+*[*]",
extended_valid_elements: "+*[*]",
verify_html: false,
cleanup: false,
cleanup_on_startup : false,
I know some of these are deprecated, but I'm willing to try anything at this point.
The issue you are running into is that TinyMCE is designed to create valid, well-formed (X)HTML. If you attempt to create table related tags but don't wrap them in a table the HTML cleanup/validation routine will always do its best to cleanup the content to make it valid.
There is no way to disable this validation.
Why don't you just wrap them in a <table>, then just remove <table> and </table> just before saving?
I have done that for something else, but with TinyMCE.
I have the full code in the textarea (where the content of the TinyMCE is), and then used javascript to remove the unwanted code (<table> and </table> in your case) before saving it to a file.
It will work this way:
IF you load the content of the textarea from a database, then just prefix and suffix the content with what you need to make TinyMCE work.
Then get the content from the textarea when you are going to save it, BUT remove the prefix and suffix before writing it to the database/ file.
Doing this should be easy, and gives you endless possibilities.
(You could either do that by javascript, or by PHP (or whatever server side language you use).)

Passing html in string in include

I have the code below and I need to pass an html element (anchor) as shown. I have tried using filters like raw and escape but it always prints out the html element as regular text. I also tried setting a new variable that contains the same string text and passed that to testLink and then applied filters to it, but same result. Any ideas how to tackle this problem?
{% include 'example.html.twig' with {'testLink': 'Hurry, Click me NOW'} %}
You cannot handle your problem in the template that is including the example.html.twig template as autoescaping will step in when the passed value is displayed in the included template. Instead, you will have to use the raw filter in example.html.twig (be careful with that solution though as the template is probably used in other places too which might not be safe).

How to add a class to the body when parent ID is matched in Kentico 6

I'm trying to add a class to the body if any parent of the current document matches specified nodeid.
For example:
If current document parent nodeid is equal to 1234 - add class "blue"
<body class="LTR Gecko Gecko28 ENUS ContentBody blue">
I it possible to achive this by using macros in webpart settings, not by editing asp?
It is not a nice solution, but it would is possible (i would look into asp.net, or custom macros)
//depence when you load jQuery the window.onload = ... , could be replaced with $(...)
{%CurrentDocument.NodeId|(equals)1234|(truevalue)<script>window.onload = function()$("body").addClass("blue");}</script>|(falsevalue)#%}
//Watchout for special-characters in the script, since it could break, the macro
Beware if you upgrade this solution, the code will be altered.
Tested with Kentico v6.0.58 (SP1), in a Rich-Text Field and Chrome 33+

drupal - jQuery, can't select any elements via jQuery

I have a form and I add a js file via drupal_add_js() in the init code of the module.
I see the first debug message, but I can't seem to select any items from the document. I just get the jQuery object returned.
But when I add the same line into the firebug, it works.
console.log('called => init()');
console.log(jQuery('#quiz-form').find('#edit-next'));
If you're trying to retrieve the value from your form element, try:
console.log(jQuery('#quiz-form').find('#edit-next').val());
Getting the jQuery object as return is perfectly fine as methods like find actually return a jQuery object. You should check the length of the jQuery object that you are getting as return i.e. console.log(jQuery('#quiz-form').find('#edit-next').length);. If the length is zero, then of course the elements are not being found. In that case you should make sure that your JS code is being called after the DOM is ready i.e. you should either wrap your code with jQuery(document).ready or use Drupal behaviors.
I figured it out by chance. The jQuery object was trying to find the selected object before the page was initialized.
I was thinking drupal_add_js in the init module was enough.
BUt I had to wrap the jquery code in the Dom Ready function as well... as we always are supposed to do.

How can I style invalid text field content in Spring MVC (JSP)

The Spring MVC JSP tag library has a tag for rendering form errors. This makes it easy to render an error message next to, say, an input text field. However, it is common practice on many websites to also style the input text field itself (with a red border maybe) to highlight a validation error.
Is there any way of doing this with the Spring JSP tags or will I have to bake my own solution?
I have never used Spring MVC JSP tags but looking at the documentation it looks like cssErrorClass is the way to go:
<form:input path="userName" cssErrorClass="error"/>
Equivalent to "class" - HTML Optional Attribute. Used when the bound field has errors.
Obviously you can now define input.error class in your CSS stylesheet.
You can use spring:bind tag around the form:input tag. In between the spring:bind tag you can use something like ${status.error ? 'error' : ''} for your style class.
status.error will be true if errors. form input field is available

Resources