extending href programmatically in typo3 - html

What's the best way to extend the attribute href programmatically in Typo3?
The links were setted by RTE like
<a class="download" target="_blank" href="fileadmin/ablage/test_material/pdf_1.pdf">
and shall be changed to
<a class="download" target="_blank" href="fileadmin/ablage/test_material/pdf_1.pdf#zoom=100">

Untested code:
you could try to add the section to the parameter
lib.parseFunc_RTE.tags.link.typolink.parameter.append = TEXT
lib.parseFunc_RTE.tags.link.typolink.parameter.append {
value = #zoom=100
if.equals.data = parameters:0
if.equals.substring = -3,3
if.value = pdf
}
or you can try to use "section"
lib.parseFunc_RTE.tags.link.typolink.section.cObject = TEXT
lib.parseFunc_RTE.tags.link.typolink.section.cObject {
value = zoom=100
if.equals.data = parameters:0
if.equals.substring = -3,3
if.value = pdf
}
BUT the most important issue is the "if" statement. I assume that the first parameter is the name of the file (i do not remember). The last 3 charachters should be "pdf". If you use DAM you need to retrieve the UID and get the filetype from there.
Just a rought guess, this could give you a hint, which params do you have:
lib.parseFunc_RTE.tags.link.typolink.parameter.append = TEXT
lib.parseFunc_RTE.tags.link.typolink.parameter.append {
data = parameters : allParams
htmlSpecialChars = 1
wrap = ?debug=|
}
Just a side note: this would be affect all RTE fields!

If there is a fixed class for that link, you could use jQuery...
jQuery(document).ready(function(){
$('.download').each(function(){
var linkhref = $(this).attr('href');
$(this).attr('href', linkhref + '#zoom=100');
});
});

This code do it.
parseFunc_RTE.tags.link.typolink.parameter.append = TEXT
parseFunc_RTE.tags.link.typolink.parameter.append {
value = #zoom=100
if.equals.data = parameters : allParams
if.equals.substring = -3,3
if.value = pdf
}

Related

Best way to adjust letter spacing every 3 chars in Ionic/Angular input box

I'd like users to enter a code and to assist them in transcribing it I'd hope to increase the spacing between every 3rd character they type. I've seen this nicely done for credit cards having 4 character spacing. This will be for an Ionic app so the simple input box coud be replaced with a customised Ionic control.
What methods have you used for this and what works best?
Open to Angular/Ionic code samples or a related web site tutorial.
Pure CSS would be nice.
Here is an other version, without jquery, works with alphanumerical and takes a configurable separator:
Typescript:
GROUP_SEPARATOR=" ";
......
format(valString) {
if (!valString) {
return '';
}
let val = valString.toString();
const parts = val.replace(/ /g, '');
return parts.replace(/\B(?=(?:\w{3})+(?!\w))/g, this.GROUP_SEPARATOR)
};
HTML
<input [(ngModel)]="input"
style="border:1px solid black" #myBudget="ngModel" (input)="input = format(input)">
DEMO
You can add space on keyup event.
Example
$('#input').on('keyup', function(e){
var val = $(this).val();
var newval = '';
val = val.replace(/\s/g, '');
for(var i=0; i < val.length; i++) {
if(i%3 == 0 && i > 0) newval = newval.concat(' ');
newval = newval.concat(val[i]);
}
$(this).val(newval);
})
I found a simpler method based on Vija's method ... Basically we match 3 non-space chars and we remove any previously added space chars. This is needed to allow the user to update or erase any chars in the text box.
A final solution may also need to adjust the position of the cursor based on where it was prior to performing the replace.
$('#input').on('keyup', function(e){
var val = $(this).val();
var newval = val.replace(/([^ ][^ ][^ ]) */g, "\$1 ").trim();
$(this).val(newval);
})

Making a simple flexible translate function in nodejs

In nodejs I have these (very long) translation files
gb.json (english)
{
"transHi":"Hello",
"transBye":"Goodbye"
}
de.json (german)
{
"transHi":"Gutentag",
"transBye":"Auf Wiedersehen"
}
I have a lot of controllers that all need these texts available in the many languages so I can call them when ever needed.
The obvious way would be something like this in my app.js:
global.gb = require('../global/language/gb.json');
global.de = require('../global/language/de.json');
And when I need a text I would call like:
myText = global.gb.transHi
myText = global.de.transHi
But!! the language is always determined by a variable
usersLanguage = "de"
myText = global.usersLanguage.transHi
And that wont work.
I also tried:
usersLanguage = "de"
myText = global.usersLanguage.transHi
Perhaps I could solve it with a function that has a long switch structure
var findText = (language,textkey) => {
switch(language) {
case "gb:
return gb.textkey
break;
case "de:
return de.textkey
break;
}
}
myText = translate(usersLanguage, "transHi");
But I cant seem to make that work either.
How would I do this in a simple and flexible way?
UPDATE: Is it possible to do this?
Any object property accessed via . can also be accessed using array index notation []. So,
var langObj = texts.gb;
is the same as
var langObj = texts["gb"];
which is also the same as
var lang = "gb";
var langObj = texts[lang];
Same for the textkey, using the .textkey you get the property called textkey, which probably doesn't exist. If you want a different property depending on the value of the variable textkey, do
var text = langObj[textkey];

Setting input value with html code crashes the input

I am trying to make a web to change the data base. The problem is that some attributes from the DB are in html format, and when I try to set the input's value to the current DB attribute, it crashes.
The code that I use is the following:
$('#projectlist').DataTable( {
"createdRow": function ( row, data, index ) {
var ele = $('td', row).eq(1);
var id_input = $('td', row).eq(0);
id_input = id_input[0].innerHTML;
ele[0].innerHTML = '<input id="'+id_input+'" value="'+ele[0].innerHTML+'" style="width:100%; height: 25px;">';
},
data: data
} );
This just sets the second element from the table to be an input with the value equal to the DB.
But when the DB has html code like this one
text \" moretext
the input finishes at the \ and following text is shown as regular text instead of input.
here's an image of the problem. As you can see the top input is how it should be showing and the bottom input has the text that doesn't stay inside in the input box, it justs contiunes like text.
like k-nut said, doing it with jquery solves the problem. If someone is interested, changing the code to this solved the problem:
var ele = $('td', row).eq(1);
var id_input = $('td', row).eq(0);
var content=ele[0].innerHTML;
id_input = id_input[0].innerHTML;
ele[0].innerHTML = '<input id="'+id_input+'" style="width:100%; height: 25px;">';
$( "#"+id_input ).val(content);

Google Documents: set heading as defined in current document

I'm writing a script that picks the paragraph where the cursor is contained, set the text to uppercase and change the paragraph heading to HEADING1.
However, the paragraph is set to the 'global' HEADING1, not to HEADING1 as it is defined in the current document. Here is the code.
function SetSceneHeading() {
var cursor = DocumentApp.getActiveDocument().getCursor();
var element = cursor.getElement();
var paragraph = [];
if (element.getType() != 'PARAGRAPH') {
paragraph = element.getParent().asParagraph();
}
else paragraph = element.asParagraph();
var txt = paragraph.getText();
var TXT = txt.toUpperCase();
paragraph.setText(TXT);
paragraph.setHeading(DocumentApp.ParagraphHeading.HEADING1);
}
Is there a way to set a paragraph to the 'current' HEADING1? Thanks.
I found a workaroud to set a paragraph to a user defined heading. Basically, you first set the heading using setHeading(), then you set to "null" the attributes that the previous operation messed up. This way the paragraph is set according to the user defined heading.
function MyFunction ()
var paragraph = ....
paragraph.setHeading(DocumentApp.ParagraphHeading.HEADING1);
paragraph.setAttributes(ResetAttributes());
function ResetAttributes() {
var style = {};
style[DocumentApp.Attribute.FONT_SIZE] = null;
style[DocumentApp.Attribute.BOLD] = null;
style[DocumentApp.Attribute.SPACING_BEFORE] = null;
style[DocumentApp.Attribute.SPACING_AFTER] = null;
return style;
}
I made a few tests, FONT_SIZE BOLD SPACING_BEFORE SPACING_AFTER seem to be the attributes that need to be reset. They may be more, according to the cases.
Unfortunately it seems that this won't be possible for now, there is an open issue that I think is relevant : issue 2373 (status acknowledged) , you could star it to get informed of any enhancement.

Using MATLAB to parse HTML for URL in anchors, help fast

I'm on a strict time limit and I really need a regex to parse this type of anchor (they're all in this format)
20120620_0512_c2_102..>
for the URL
20120620_0512_c2_1024.jpg
I know its not a full URL, it's relative, please help
Here's my code so far
year = datestr(now,'yyyy');
timestamp = datestr(now,'yyyymmdd');
html = urlread(['http://sohowww.nascom.nasa.gov//data/REPROCESSING/Completed/' year '/c2/' timestamp '/']);
links = regexprep(html, '<a href=.*?>', '');
Try the following:
url = 'http://sohowww.nascom.nasa.gov/data/REPROCESSING/Completed/2012/c2/20120620/';
html = urlread(url);
t = regexp(html, '<a href="([^"]*\.jpg)">', 'tokens');
t = [t{:}]'
The resulting cell array (truncated):
t =
'20120620_0512_c2_1024.jpg'
'20120620_0512_c2_512.jpg'
...
'20120620_2200_c2_1024.jpg'
'20120620_2200_c2_512.jpg'
I think this is what you are looking for:
htmlLink = '20120620_0512_c2_102..>';
link = regexprep(htmlLink, '(.*)', '$2');
link =
20120620_0512_c2_1024.jpg
regexprep works also for cell arrays of strings, so this works too:
htmlLinksCellArray = { '20120620_0512_c2_102..>', '20120620_0512_c2_102..>', '20120620_0512_c2_102..>' };
linksCellArray = regexprep(htmlLinksCellArray, '(.*)', '$2')
linksCellArray =
'20120620_0512_c2_1024.jpg' '20120620_0512_c2_1025.jpg' '20120620_0512_c2_1026.jpg'