sap.m.FormattedText not working in the sap.m.CustomTile - css

I want to make demo with sap.m.FormattedText nested in the sap.m.CustomTile in the jsbin. I do not know why I got this insted of the text SYSTEM SIZE:
The string I used is:
var sString = "<p style="font-size:20px; color:#808080; padding-left:40px; " > SYSTEM SIZE </p>" ;
var oFtext = new sap.m.FormattedText();
oFtext.setHtmlText(sString);
All code is in the jsbin example.
When I use the same string in the view it works:
<CustomTile>
<Vbox>
<FormattedText htmlText='
<p style="font-size:20px; color:#808080; padding-left:40px; margin-bottom:0px; "> SYSTEM SIZE </p>
'/>
</Vbox>
</CustomTile>
Thanks for any advice.

You are escaping the <, > and ' characters. This is necessary on the xml file (it is actually just part of the specification of xml, as you can see in this question on SO) but not in the js file.
Write the html normally and it will work: <p style='font-size:20px; color:#808080; padding-left:40px; ' >; SYSTEM SIZE </p>"

Related

Inserting a comma into text copied from a website

I often encounter an annoying phenomenon. I select an address in the browser (Firefox):
Example from yelp.com
Copy it into my adress bar, using the !maps DuckDuckGo bang:
We immediately see the problem: house number and zip code do not get separated, and more often than not Google Maps then fails to find the address (unsurprisingly).
The code in this case is:
<address>
Hans-Sachs-Str. 8<br>80469 Munich<br>Germany
</address>
I can imagine similar code with <p> or <div> instead of address; the relevant part seems to be how <br> will be copy-pasted.
The following is also conceivable:
<tr><td>Hans-Sachs-Str. 8</td></tr>
<tr><td>80469 Munich</td></tr>
Which copies in just the same way.
So if I put an address on my website (or write a user style), how can I make addresses copy-paste in a helpful way, e.g. with a comma between the individual fields/lines?
Answers with HTML5 and CSS3 are fine, and current browsers can be required; I don't care about backwards compatibility. Answers without Javascript are preferred.
I tried br::before { content: ", "; } but that didn't work.
I could only do it with JS, you will need to inject with greasemonkey or some other extension.
var commaHtml = '<span class="insertedComma">, </span>';
document.querySelectorAll('address').forEach(function(a){
a.querySelectorAll('br').forEach(function(b){
b.insertAdjacentHTML('beforebegin', commaHtml);
});
});
.insertedComma {
color: red;
/*opacity: 0; uncomment this line to make red commas disappear*/
}
<address>
Hans-Sachs-Str. 8<br>
80469 Munich<br>
Germany
</address>
Hack #1: Include an invisible comma.
<address>
Hans-Sachs-Str. 8<span style="opacity: 0;">,</span><br>
80469 Munich
</address>
This is actually quite unintrusive since it won't even show up in the selection, only in the pasted text.
Disadvantage: can't insert this automatically into existing websites without JS. (Or can I?)
If you insert presentational content using CSS pseudo-elements (::before and ::after), you will not be able to copy that content onto the clipboard.
So, I think you will have to insert any commas using javascript and DOM manipulation.
Here is an alternative javascript approach:
var address = document.getElementsByTagName('address')[0];
var addressLines = address.querySelectorAll('.strasse, .stadt, .land');
for (var i = 0; i < (addressLines.length - 1); i++) {
var comma = document.createElement('span');
comma.classList.add('comma');
comma.textContent = ',';
address.insertBefore(comma, addressLines[i]);
address.insertBefore(addressLines[i], comma);
}
span {
display: inline-block;
float: left;
}
.comma + span {
clear: left;
}
<address>
<span class="strasse">Hans-Sachs-Str. 8</span>
<span class="stadt">80469 Munich</span>
<span class="land">Germany</span>
</address>

HTML form in Adobe Animate CC

How to insert a HTML form to a website designed using Adobe Edge Animate CC. Is there any simple way to implement ?
Please Help!
You can add your code on the stage when clicking on the {} brackets.
Inserting code like so:
sym.$('input_box_username').html("<input type='text' id='input_box_username' placeholder='Username'" + " maxlength='60' " + " style='background-color:white; border:1px solid #0B76d1; padding-left: 5px; width:550px; height:26px; font-size:14px;'>")
sym.$('input_box_password').html("<input type='password' id='input_box_password' placeholder='Password'" + " maxlength='40' " + " style='background-color:white; border:1px solid #0B76d1; padding-left: 5px; width:550px; height:26px; font-size:14px;'>")
This example will generate two input field one for a username and one for a password.
The rest of your html code can inserted like so.
In animate in your javascript action-windows, you can refer to a form and the input fields in it - and later (after you have published your animation) you can add this form to your html - next to your canvas, or overlapping it.

QString.replace not working

I am trying to process HTML data held in a QString. The data has encoded HTML tags, e.g. "<" etc. I want to convert these to the appropriate symbols.
I have been trying a number of approaches but none seem to work, which suggest I am missing something really simple.
Here is the code (amended to fix typos reported by earlier comments):
QString theData = "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Arial'; font-size:20pt; font-weight:400; font-style:normal;">
<table border="0" style="-qt-table-type: root; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;">
<tr>
<td style="border: none;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; color:#4cb8ff;">This is text on the second page. This page contains a embedded image,</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; color:#4cb8ff;">and audio.</span></p></td></tr></table></body></html>";
QString t2 = theData.replace("&", "&").replace("<", "<").replace(">", ">").replace(""", "'");
The value of t2 however is the same as theData after the replaces.
There is no definition of t1 in your code, I suppose you mean theData (and no double dot). The QString::replace functions alter the value of the string and return a reference of this.
QString s = "abc";
s.replace("a", "z").replace("b", "z");
// s = "zzc";
// if you don't want to alter s
QString s = "abc";
QString t = s;
t.replace("a", "z").replace("b", "z");
But there is better way to escape/unescape html strings:
// html -> plain text
QTextDocument doc;
doc.setHtml(theData);
QString t2 = doc.toPlainText();
// plain text -> html
QString plainText = "#include <QtCore>"
QString htmlText = plainText.toHtmlEscaped();
// htmlText == "#include <QtCore>"
If you only want to convert html entities, I use the following function, complementary to QString::toHtmlEscaped():
QString fromHtmlEscaped(QString html) {
html.replace(""", "\"", Qt::CaseInsensitive);
html.replace(">", ">", Qt::CaseInsensitive);
html.replace("<", "<", Qt::CaseInsensitive);
html.replace("&", "&", Qt::CaseInsensitive);
return html;
}
In all cases, it should hold that str == fromHtmlEscaped(str.toHtmlEscaped()).

CSS:after encoding characters in content

I am using the following CSS, which seems to be working:
a.up:after{content: " ↓";}
a.down:after{content: " ↑";}
The characters however cannot seem to be encoded like this, as the output is literal and shows the actual string:
a.up:after{content: " ↓";}
a.down:after{content: " ↑";}
If I can't encode it, it feels like I should use something such as .append() in jQuery, as that supports the encoding. Any ideas?
To use encoded Unicode characters in content you need to provide either the characters themselves (as you do), or their UTF-8 escape sequences instead of HTML entities:
a.up:after { content: " \2193"; }
a.down:after { content: " \2191"; }
Why do you want to encode those characters anyway? Remember, you're writing CSS, not HTML. Your code:
a.up:after{content: " ↓";}
a.down:after{content: " ↑";}
is perfectly valid, as long as you save the file with UTF-8 encoding and send the appropriate header:
Content-Type: text/css; charset=utf-8
Encoding characters is only used in HTML so that there is no ambiguity between content and tags. Thus, you would encode< as < so that the browser doesn't think it's the beginning of a tag. Stuff like ↓ are just commodities for people who don't know how to use utf-8 (or can't, for whatever reason) :).
Just want to add that if you want to set dynamically the value of content via the attr() function, the above won't work. See
document.getElementById('wontwork').setAttribute('data-sym', ' \2714 ');
document.getElementById('willwork').setAttribute('data-sym', ' \u2714 ');
button::before {
content: attr(data-sym);
}
* {
font-size: 30px
}
<button id='wontwork' data-sym='to-be-replaced'>not rendered</button>
<button id='willwork' data-sym='to-be-replaced'>rendered !</button>

CSS text-transform capitalize on all caps

Here is my HTML:
small caps &
ALL CAPS
Here is my CSS:
.link {text-transform: capitalize;}
The output is:
Small Caps & ALL CAPS
and I want the output to be:
Small Caps & All Caps
Any ideas?
You can almost do it with:
.link {
text-transform: lowercase;
}
.link:first-letter,
.link:first-line {
text-transform: uppercase;
}
It will give you the output:
Small Caps
All Caps
There is no way to do this with CSS, you could use PHP or Javascript for this.
PHP example:
$text = "ALL CAPS";
$text = ucwords(strtolower($text)); // All Caps
jQuery example (it's a plugin now!):
// Uppercase every first letter of a word
jQuery.fn.ucwords = function() {
return this.each(function(){
var val = $(this).text(), newVal = '';
val = val.split(' ');
for(var c=0; c < val.length; c++) {
newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length) + (c+1==val.length ? '' : ' ');
}
$(this).text(newVal);
});
}
$('a.link').ucwords();​
Convert with JavaScript using .toLowerCase() and capitalize would do the rest.
Interesting question!
capitalize transforms every first letter of a word to uppercase, but it does not transform the other letters to lowercase. Not even the :first-letter pseudo-class will cut it (because it applies to the first letter of each element, not each word), and I can't see a way of combining lowercase and capitalize to get the desired outcome.
So as far as I can see, this is indeed impossible to do with CSS.
#Harmen shows good-looking PHP and jQuery workarounds in his answer.
I'd like to sugest a pure CSS solution that is more useful than the first letter solution presented but is also very similar.
.link {
text-transform: lowercase;
display: inline-block;
}
.link::first-line {
text-transform: capitalize;
}
<div class="link">HELLO WORLD!</div>
<p class="link">HELLO WORLD!</p>
HELLO WORLD! ( now working! )
Although this is limited to the first line it may be useful for more use cases than the first letter solution since it applies capitalization to the whole line and not only the first word. (all words in the first line)
In the OP's specific case this could have solved it.
Notes: As mentioned in the first letter solution comments, the order of the CSS rules is important! Also note that I changed the <a> tag for a <div> tag because for some reason the pseudo-element ::first-line doesn't work with <a> tags natively but either <div> or <p> are fine.
EDIT: the <a> element will work if display: inline-block; is added to the .link class. Thanks to Dave Land for spotting that!
New Note: if the text wraps it will loose the capitalization because it is now in fact on the second line (first line is still ok).
JavaScript:
var links = document.getElementsByClassName("link");
for (var i = 0; i < links.length; i++) {
links[i].innerHTML = links[i].innerHTML.toLowerCase();
}
CSS:
.link { text-transform: capitalize; }
What Khan "ended up doing" (which is cleaner and worked for me) is down in the comments of the post marked as the answer.
captialize only effects the first letter of the word. http://www.w3.org/TR/CSS21/text.html#propdef-text-transform
You can do it with css first-letter!
eg I wanted it for the Menu:
a {display:inline-block; text-transorm:uppercase;}
a::first-letter {font-size:50px;}
It only runs with block elements - therefore the inline-block!
May be useful for java and jstl.
Initialize variable with localized message.
After that it is possible to use it in jstl toLowerCase function.
Transform with CSS.
In JSP
1.
<fmt:message key="some.key" var="item"/>
2.
<div class="content">
${fn:toLowerCase(item)}
</div>
In CSS
3.
.content {
text-transform:capitalize;
}
If the data is coming from a database, as in my case, you can lower it before sending it to a select list/drop down list. Shame you can't do it in CSS.
After researching a lot I found jquery function/expression to change text in first letter in uppercase only, I modify that code accordingly to make it workable for input field. When you will write something in input field and then move to another filed or element, the text of that field will change with 1st-letter capitalization only. No matter user type text in complete lower or upper case capitalization:
Follow this code:
Step-1: Call jquery library in html head:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
Step-2: Write code to change text of input fields:
<script>
$(document).ready(function(){
$("#edit-submitted-first-name,#edit-submitted-last-name,#edit-submitted-company-name, #edit-submitted-city").focusout(function(){
var str=$(this).val();
str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
$(this).val(str);
});});
</script>
Step-3: Create HTML input fields with same id's you use in jquery code like:
<input type="text" id="edit-submitted-first-name" name="field name">
The id of this input field is: edit-submitted-first-name (It using in jquery code in step-2)
**Result:
Make sure the text will change after you move your focus from that input field at another element. Because we using focus out event of jquery here.
Result should like this: User Type: "thank you" it will change with "Thank You".
**
Best of luck
The PHP solution, in backend:
$string = 'UPPERCASE';
$lowercase = strtolower($string);
echo ucwords($lowercase);
I know this is a late response but if you want to compare the performance of various solutions I have a jsPerf that I created.
Regex solutions are the fastest for sure.
Here is the jsPerf: https://jsperf.com/capitalize-jwaz
There are 2 regex solutions.
The first one uses/\b[a-z]/g. Word boundary will capital words such as non-disclosure to Non-Disclosure.
If you only want to capitalize letters that are preceded by a space then use the second regex
/(^[a-z]|\s[a-z])/g
if you are using jQuery; this is one a way to do it:
$('.link').each(function() {
$(this).css('text-transform','capitalize').text($(this).text().toLowerCase());
});
Here is an easier to read version doing the same thing:
//Iterate all the elements in jQuery object
$('.link').each(function() {
//get text from element and make it lower-case
var string = $(this).text().toLowerCase();
//set element text to the new string that is lower-case
$(this).text(string);
//set the css to capitalize
$(this).css('text-transform','capitalize');
});
Demo
all wrong it does exist --> font-variant: small-caps;
text-transform:capitalize; just the first letter cap

Resources