Wordpress Editor converts ampersand to & - javascript

when I am setting the src of an iframe dynamically with the following javascript in Wordpress:
jQuery(document).ready(function(){
jQuery('iframe').attr('src', 'http://someurl.com/?originid=PORTAL&tijdsblokstart=1700&datum=2014-05-19');
});
The last 2 parameters are not picked up. I know it has someting to do with the encoding of the ampersand, but I tried everything...I'm lost now.
- &
- &
- &
- creating the whole iframe in jQuery
The src has to be set dynamically.
Thanks!

I fixed my issue by creating a function in an external js-file that generates the url for me. So avoid using the ampersand in the Wordpress editor. I would love to hear if someone comes up with a better solution.
http://codex.wordpress.org/Using_Javascript

Here's a workaround that worked for me:
char = '&';
char = char.replace('amp;', '');
console.log(char);

If your problem occurs in post content, there is no universal solution.
Indeed, the & is replaced by & by the wptexturize function from wp-includes\formatting.php:
// Replace each & with & unless it already looks like an entity.
$curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&', $curl );
It's hooked to the the_content filter in file wp-includes\default-filters.php :
add_filter( 'the_excerpt', 'wptexturize' );
The problem is that you can remove this filter but you will loose a lot of formating done by this huge wptexturize function.
One solution for op would be to find a way to remove the ampersand from the code. To do this, you can use jQuery.param to generate the querystring part of the url:
jQuery(document).ready(function(){
jQuery('iframe').attr('src', 'http://someurl.com/?' + jQuery.param({originid: 'PORTAL', tijdsblokstart: 1700, datum: '2014-05-19'}));
});
A really dirty solution would be:
to register a filter to execute before the wptexturize one using priority 9 (by default, priority is 10) so it change your ampersand to something really unique that the wptexturize function will not alter
to register a filter to execute after the wptexturize one using priority 11 that changes back your ampersand subtitute to a real ampersand

Related

amp value replace in place

I have an amp-list which loads bunch of data and I show them in their respective placeholders just nice and easy. What I intend to do is get a value and run a simple script on it. Let's think I have
<div>{{title}}</div>
where title is: 'This-is-my-title'
now I would like to replace the '-' in title, I know I could do it with javascript using title.replace(/-/g,' '), how can I do that in place?
I tried
<div>{{title.replace(/-/g,' ')}}</div>
but no luck :(
In plain javascript the following:
title = 'This-is-my-title'; title.replace(/-/g, ' ');
gives you "This is my title".
I am guessing you are using angular, in that case the text within {{ }} is not evaluated as a pure javascript expression. You could write an angular filter to apply to the expresssion (as described in Angular filter to replace all underscores to spaces ). It would probably be easier to handle this in the controller behind the template. Something like:
$scope.title = $scope.title.replace(/-/g,' ');
Looks like you are using amp-mustache. I don't think there is a way for you to use custom JavaScript in Mustache.js here, and restrictions from AMP prevent you to create some kind of function that you can call in {{}}. I would suggest processing in the backend before sending. (Also unfortunately, there are no other templates other than mustache available at this point)
There is a workaround on math using amp-bind here: AMP Mustache and Math
So probably after loading the JSON with amp-state, something like
myItems.map(entry => ({
myString: entry.myString.split('').map(c => c == '-' ? ' ' : c).join('')),
})
might work (I have not tested myself but worth a try, check whitelisted functions here: https://www.ampproject.org/es/docs/reference/components/amp-bind#white-listed-functions) but might still be a pain performance-wise (amp-bind has quite a bit overhead)
Edit: this actually looks quite promising, just found out actually amp-list with amp-bind do accept object for [src], as described in the doc (learning something new myself): https://www.ampproject.org/docs/reference/components/amp-bind
(checked amp-list source code and should work)

Open Oracle Apex URL with JavaScript when giving parameters

when i use javascript eval() to open apex url from js i have no problem when i use eval() like this
eval("f?p=&APP_ID.:7:&SESSION.");
but when i wanna pass parameters with eval() like this
eval("f?p=&APP_ID.:7:&`SESSION.:P7_ID:8461,P7_ALLOWCHANGE:1,P7_WFDEF_ID:69004.");`
i get this error: SyntaxError: expected expression, got ':'
then these parameters automatically added after generating url
javascript:apex.navigation.dialog('f?p=101:7:28809985622510:::::\u0026p_dialog_cs=_7P7TVFV5LTQPjeyg-bGqSKpcYM',{title:'Workflow State',height:'auto',width:'720',maxWidth:'960',modal:true,dialog:null},'t-Dialog-page--standard '+'',this);:P7_ID:8461,P7_ALLOWCHANGE:1,P7_WFDEF_ID:69004.;
what should i do?
The best way would to be to use apex_page.get_url
It is so much simpler to use than apex_util.prepare_url
https://docs.oracle.com/cd/E59726_01/doc.50/e39149/apex_page.htm#AEAPI30190
I don't know about your eval call, but this APEX URL syntax is wrong:
f?p=&APP_ID.:7:&`SESSION.:P7_ID:8461,P7_ALLOWCHANGE:1,P7_WFDEF_ID:69004.
All the item names should be listed together, then all the values together - and after the correct number of colon separators:
f?p=&APP_ID.:7:&SESSION.::::P7_ID,P7_ALLOWCHANGE,P7_WFDEF_ID:8461,1,69004
I also removed the spurious back-tick character from before "SESSION".
Apart from what Tony Andrews covered, here are a few more issues with your URL:
1. it's APP_SESSION - not SESSION. Here's documentation on built in substitution strings.
2. Your items are not substituted properly. Read this documentation page more details on substitutions in APEX.
Here's documentation on understanding APEX URL syntax.
Secondly, here's what you would try. Create a hidden page item and use APEX_UTIL.PREPARE_URL function and generate valid url, assign to the item. And use that item as url in your javascript. I haven't tried this, but this would be a better approach, I think.
Also prepare url like this:
APEX_UTIL.PREPARE_URL('f?p=' || :APP_ID ||':7:' || :APP_SESSION || :::' ||:P7_ID: ',' || :P7_ALLOWCHANGE || ',' || :P7_WFDEF_ID || ':8461,1,69004')
Here's another great resource to understand apex url and how to pass variables:
http://dgielis.blogspot.in/2015/01/understanding-apex-url-passing.html

Truncate a string after match a specific word in smarty or javascript/jQuery

I am working on a website but somehow I have sometimes little bug coming from the add of content after the end of some string.
For example :
style="background-image:url({$sub.image});" return
style="background-image:url(http://blablalba.fr/phoenix.jpg%3Fv%3D1);"
As you can see there is %3Fv%3D1 after the end on the link (after .jpg). I don't know where this is coming from and I'd like to erase it.
So my question is : in smarty is there a way to truncate a String after matching a word ?
And if it is not possible, what is the easiest way in Js/jQuery ?
I tough of this Regex to match the correct string : /^(.*?\.jpg)/
So it lead me to this :
$('.append').each('li',function(){
var newLink = $(this).find('div').css('background-image').match(/^(.*?\.jpg)/);
$(this).find('div').css('background-image',newLink);
})
But this is still buggy so if someone as a better idea of how shall I do this ?
Here is a JsFiddle if it can provide some help.
Edit + Answer
Ok so as has said #Hitmands just below it was a problem of URI encoding.
So this is the clearest and smartest solution :
$('.imgLittle').each(function() {
newLink = decodeURIComponent($(this).css('background-image'));
$(this).css('background-image',newLink)
})
And here is the final (working) JsFiddle.
Hope this could help someone once.
If you try to exec this window.decodeURIComponent("%3Fv%3D1") in your console it returns a simply "?v=1", this could be a way to manage the client-caching... when the v (version?) param changes it forces the browser to download the resource even is already cached...
I think that this is an important information that you cannot strip!
A smart solution could be a simply decoding of this param.... you should, but I'm not sure, try http://www.smarty.net/docs/en/language.modifier.unescape.tpl...
If isn't possible to decode the URI Component via smarty, you can do it via Javascript using the code that you posted below with the window.decodeURIComponent instead of regex-stripping.

Open SSRS URL in New Window

I have a report that passes an id that is used to access salesforce.com. I want to open SFDC as a new page from the URL hyperlink. However, nothing I do seems to be working!
="javascript:void(window.open('https://na5.salesforce.com/& Fields!id.Value,'_blank'))"
Fields!id!Value is the SFDC id that is being passed. I'm trying this in the expression to no avail!
I know it is something VERY simple but I'm just not finding it. Thanks in advance for the assistance!
UPDATE!!!
Figured it out!!! For the record, the syntax is:
="javascript:void(window.open('https://na5.salesforce.com/" & Fields!id.Value & "'))"
For the record, the problem with your original syntax was that you were trying to go from referencing an SSRS field to entering a string without separating the two properly. If you wanted your previous syntax to work (without removing the target window's name (i.e., '_blank'), you would do it like this:
="javascript:void(window.open('https://na5.salesforce.com/" & Fields!id.Value & "','_blank'))"
I struggled with this for a long time, but you can make these pretty complex as long as you're careful to put everything together correctly. You can also add multiple javascript commands (but no functions) in the same action expression. Below is one of my most complicated SSRS Go-to-URL Action commands:
="Javascript:"
& IIF(left(Fields!Name.Value,11)="RESTRICTED-",
"alert('Restricted!'); ","") & IIF(Fields!Name_Alert.Value = 1, "alert('Alternate Alert!'); ","")
& "void(window.open('"
& Globals!ReportServerUrl
& "/Pages/ReportViewer.aspx?%2fJPD%2fPO_Dashboard%2fJuvenile_Profile&rs:Command=Render"
& "&rc:Parameters=true"
& "&Emp_Number="
& Parameters!Param1.Value
& “&ID=" & Fields!ID.Value & "'));"
The key is to make sure that any and all necessary single quotes required by javascript show up inside a string (i.e., "'").
Nonono, don't use ="javascript:void(window.open(.
First, it breaks PDF & Excel reports,
and second, it doesn't work in IE11 and possible also < 11.
Tested it, worked only in Chrome for me.
And third, it's a mess to put it together.
There's a far easier & better solution:
Add &rc:LinkTarget=_blank to your report access URL, like:
https://your-domain.com/ReportServer/Pages/ReportViewer.aspx?%2fJPD%2fPO_Dashboard%2fJuvenile_Profile&rs:Command=Render&rc:LinkTarget=_blank
and it will open in a new window tab.
Edit:
If you want to make your own display page:
This is how you get all reports:
USE [ReportServer$MSSQL_2008_R2]
SELECT
[ItemID]
,[Path]
,[Name]
,[ParentID]
FROM [Catalog]
WHERE Type = 2
And this is how you can display all folders/reports at level x
;WITH CTE AS
(
SELECT
[ItemID]
,[Path]
,[Name]
,[ParentID]
,0 AS lvl
,CAST([Name] AS nvarchar(MAX)) AS RecursivePath
FROM [Catalog]
WHERE [ParentID] IS NULL
UNION ALL
SELECT
[Catalog].[ItemID]
,[Catalog].[Path]
,[Catalog].[Name]
,[Catalog].[ParentID]
,cte.lvl +1 AS lvl
,CAST(cte.RecursivePath + '/' + [Catalog].[Name] AS nvarchar(MAX)) AS RecursivePath
FROM CTE
INNER JOIN [Catalog]
ON [Catalog].ParentID = CTE.ItemID
)
SELECT * FROM CTE
WHERE lvl = 1
ORDER BY lvl, Path
If you only want the folders:
WHERE Type = 1
If you only want the data-sources:
WHERE Type = 5
If you are wanting to link to an external URL and want the links to work both within the report viewer and if you export to Excel for example, I use the following expression.
=IIF(
Globals!RenderFormat.Name = "RPL",
"javascript:void(window.open('http://www.domain.com/page/" & Fields!Page_ID.Value & "','_blank'))",
"http://www.domain.com/page/" & Fields!Page_ID.Value
)
It will use the JavaScript if viewing from within the report in the browser and standard linking otherwise.
Here is what I had used; it will open the ChildReport in a new tab, with a parameter voucher_id and its value passed from a dataset.
="javascript:void window.open(" &"'"& Globals!ReportServerUrl &"/Pages/ReportViewer.aspx?"&Globals!ReportFolder &"/JournalVoucher&voucher_id="&Fields!account_voucher_id.Value &" ','_blank')"

Remove prefix with unknown characters in JavaScript

I have a web page that the title is changed from 'Pagename' to '(1) Pagename' when there is an update on the page. That number increments to 50 each time there is a new update and then is maxed out showing '(50+) Timeline'.
When logging page views, Google Analytics shows the '(n) Pagename', which I don't want. So I found out how to manually change to logged page title, _gaq.push(["_set", "title", 'new title']);.
So my question is, how do I most efficiently remove the (1-50)/(50+) prefix and just get 'Pagename'? Is regex best for this?
This is what I'm using based on the answer from Ross:
var window_title = window.title.replace(/^\(\d+\+?\)\s/, '');
_gaq.push(["_set", "title", window_title]);
Yes, RegEx can do that.
window.title.replace(/^\(\d+\+?\)\s/, '');
Of course it depends on what software your site is using as perhaps it would be possible to just output the page title without that prefix in the relevant part of the template. So echoing that directly into the Google Analytics tag. But I think the above javascript is probably the easier solution to implement.

Categories

Resources