Preserving the case of a title in ExpressionEngine? - expressionengine

Under EE 1, I was able to hack the source to allow me to retain url titles with the exact case of the title. That is, I was able to keep it from forcing all url titles to be lower case.
I need to replicate the same behaviour on EE 2, but I am not quite managing so far.
What I have done so far is this:
In <system>/expressionengine/modules/channel/mod.channel_standalone.php:
commented out this line: NewText = NewText.toLowerCase();
added “A-Z” to this line: NewText = NewText.replace(/[^a-z0-9-_]/g,’‘);
In <system>/expressionengine/helpers/EE_url_helper.php:
removed strtolower() from this section:
if ($lowercase === TRUE)
{
$str = strtolower($str);
}
added “A-Z” to this line: [^a-z0-9\-\._]
I don’t know for sure if all of these changes were actually needed, but I think so. By the look of it, the changes to mod.channel_standalone.php should take care of any submissions via a stand-alone entry form and the changes to EE_url_helper.php should take care of regular postings.
It almost does, except for the live URL. The URL generated as I type a title is generated in lower case. However, if I delete it before I save the post, it saves the post with the same case in the url title as the title. At least, it does so most of the time. Sometimes, it does get saved with the lower case url.
If anyone might be able to tell me how to get the live URL title to co-operate as well, I would be very grateful.

This is happening in themes/javascript/compressed/jquery/plugins/ee_url_title.js.
It may be a bit difficult to find since the Javascript is compressed, but the expression you will want to edit is: a = (k + a).toLowerCase().replace(d, c);

Related

How to use regex inside objectContaining

Essentially trying to test the result of a function that contains 3 irrelevant string properties (irrelevant to this question). But a 4th property that is a ISO 8601 string that gets created when the function gets executed. I have no way of knowing what this exact value will be, so I want to test the property via regex. Usually I'd do something like this (which would work but not as clean):
expect(desiredProperty).toMatch(ISOPattern); // ISOPattern = regex i made that works
But doing it this way would mean i need to write this expect for every single property, whereas something like this is more clean and easier to read:
expect(result).toEqual(
expect.objectContaining({
id: mockEmail,
otpPassword: mockOtpPassword,
expire: 1000 * 60 * 60,
expire_at: expect.toMatch(ISOPattern), // NOT WORKING, FAILS
})
);
So I am wondering, is doing something like the above possible at all? I could just not check that property in my expect.objectContaining function, and add another expect to do what i mentioned above. But again, wondering if I could have the best of both worlds.
Not sure if I formatted my post right but essentially this is what I ended up doing (i mentioned this in the OP):
expect(result).toEqual(
expect.objectContaining({
id: mockEmail,
otpPassword: mockOtpPassword,
expire: 1000 * 60 * 60
})
);
expect(result.expire_at).toMatch(ISOPattern);
So the idea here was to get rid of the extra expect call (if you notice here I am checking against the same object result, but I wont know the value of the date and its not important anyways so I just want to check some regex I wrote (whether this works or not is irrelevant although the regex works for sure), and somehow do the regex check inside the expect.objectContaining function, but I dont think I did a good job at formatting my question right so thats probably on me.
Open to anyones help if they see a way to do what im talking about.
The code in this solution is what I am using now, the question I am trying to ask is if theres a better way to do this. The regex working is not relevant, although I know 100% it does work. I did not provide this regex because its literally not what I am asking or relevant to the solution I am seeking.

Why can I change a site's cookies in the dev tools, but not from the console?

I've spent at least five hours trying to change the cookies of a website, which in my case was Facebook, through the console.
It appears that if I blank out c_user in the dev tools, I'm logged out. But when I tried to achieve the same thing in the console, nothing happens. I have tried the following two methods:
document.cookie[0]="c_user=0";
document.cookie.replace("c_user", "94029r23r");
You are not doing the JS correctly. What is important to understand is that document.cookie returns a string with all the cookie names and values. Let's look at what your code does to that string.
document.cookie[0]="c_user=0";
Taking element zero of a string returns the first character. In this case, you will get the first character of the name of the first cookie. Setting a character to a string is just nonsense, it does nothing and does not change the original string - document.cookie.
document.cookie.replace("c_user", "94029r23r");
I assume you are expecting this to replace the name of the cookie? Only problem is that the JS function replace does not change the input. It returns a copy with the replacements made on it. So again, you do not modify document.cookie.
For the correct way to do it, see this question. Or if you want something quick and dirty that removes the value, try this:
document.cookie = document.cookie.replace("[the session id]", "");

Mathjax Display Of $1<x<2$

Experimenting with Mathjax on my site, I face a problem when I type in
$1<x<2$
The outcome will be as follows
This, for example, has no issues.
$x<1\text{ or }x>2$
How do I make the first one display normally?
I have attached the issue at http://teach.sg/mathematics/additional-mathematics/mathjax/.
Since < is used to start a tag in HTML, the browser considers 1<x to be a 1 followed by a tag beginning <x, and everything up to the next > becomes part of that tag. This happens long before MathJax has a chance to look for mathematics on the page, so MathJax is not able to process this math as you intended it.
You have already identified one solution (using \lt and \gt) You can also just use spaces in most cases: $1 < x < 2$.
Instead of using $1<x<2$, use $1\lt x \lt 2$.

modx - getPage - [[+pageNav]] Placeholder always has a value

I try to hide the getPage [[+pageNav]] Placeholder if there is no pagination. But I can't do the following.
[[!+pageNav:notempty=`<ul class="overview__pagination">[[!+pageNav]]</ul>`]]
Does someone know how I can hide the element with an apropriate output filter? (without own extra snippet). I also tried the following and some other (not likely to work variations).
[[!+pageNav:isnot=``:then=`<ul class="overview__pagination">[[!+pageNav]]</ul>`]]`
Are you calling that code in a chunk that is cached?
Otherwise i've experienced this aswell and it seems custom placeholders sometimes behave that way, it's probably due to the fact that they actually have some unprocessed value during the IF computation but when it's actually output you see nothing. Or that the value is somehow "null" instead of "" while modx output filter might do a strict comparison.
If you're not calling it in a cached chunk or part of code, i suggest first trying with another getPage placeholder such as pageCount or total.
Like:
[[!+pageCount:gt=`1`:then=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
If that still doesn't work, a last resort in the form of a simple snippet will always solve it, like:
[[!outputPagination? &total=`[[+total]]` &limit=`XX` &output=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
In snippet:
if ($total > $limit) {
return $output;
}
Shouldn't it be...
[[!+page.nav:notempty=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
Well, there is a much more easier way to do it than in the first answer. It's like TheMistaC says, even if my answer is a lot easier:
[[!+page.nav:notempty=`
[[!+page.nav]]
`]]
I use it to display a list of articles with getResources, so I know this works fine.

Checking if an element exists without losing time in Capybara

I like to keep things DRY, that's why I want to have the following in one of my steps:
if first(:css, "#blabla") != nil
find_by_id(blabla).click
end
find_by_id(....)
....
This means, that it will look for a certain element, and if it exists, it will click on it. If not, I will not lose time (my default wait time is 20 secs, which will be used if I put find instead of first there.
The main issue is that I don't want to lose time when checking for a certain element in this case, but I am also wondering if this is a good approach.
I see the issue that your code does unnecessary second query to browser (you already have first(:css, "#blabla") so no need to do find_by_id(blabla))
I propose you to find element using one query:
el = first('#blabla')
el.click unless el.nil?
Note that there is no losing time here as first doesn't block.
However, first doesn't check that there no other elements on the page. You can add :maximum to check it:
el = first('#blabla', maximum: 1)
el.click unless el.nil?
When you're using #find to decide on element presence, you should reduce the wait time for just that call:
if page.has_css?('#blabla', wait: 0)
# Do something
end
However, in your special case, the suggested solution is even better, because it saves you multiple "find" calls for the same element.

Resources