Detecting duplicate HeaderItems

Permalink
Hi!

I've got several blocks that add jQueryUI to the header.

First problem: In edit mode, there is already a custom jquery ui loaded, which comes from concrete5 itself.

First problem is fixed by determining if we're logged in or not and loading the jqueryui file only if we're logged out.

Second problem: When I add the same block or a different one using the jQueryUI library, I run into problems.. And I don't know howto solve this, except if there was a duplicate detection in the header. For files with the same (size and) filename (or with hashes) but different blockPaths.

I'm building a larger application with Concrete5.4 and I've many packages that I've built including several blocks. I'm testing the entire thing with my theme disabled, because I find the default theme loads faster for testing functionality and I want my application work on every theme at the end.

That's why I didn't include the jQueryUI library globaly in my theme.

Can someone please give an advice on this?

Regards
Fernandos

Fernandos
 
Remo replied on at Permalink Reply
Remo
file sizes/hashes won't work.

What happens if you use jquery ui 1.7.1 and c5 uses jquery ui 1.7.1+?

We would have to create a more advanced include system with "labels" and "versions"?

in the core:
- label1: "jquery ui"
- version1: "1.7.1"

in your addon:
- label2: "jquery ui"
- version2: "1.7.2"

c5 could then check for the higher version and ignore the other include.. However, even in this case you can't be sure that it works. Windows dll hell with web applications (:
Fernandos replied on at Permalink Reply
Fernandos
Remo that's a fantastic idea!

addHeaderItem($label,$versionControl,$script,$path);

$v->addHeaderItem('myjqeryui',true,'<script type="text/javascript" src="' . $url->getBlockTypeAssetsURL($bt) . '/js/ui/jquery-ui-1.8.min.js"></script>','CONTROLLER');

I'm very common with the htmlHelper file, because I've added a patch for it, which adds a load only for specific ie-version feature.

Here you go:http://www.concrete5.org/private/bugs/fixes/htmlhelper-patch/...

Here's another patch I made:http://www.concrete5.org/private/bugs/fixes/header_required-replace...


But both patches aren't accessible from anywhere, because the bugs section is probably undergoing maintainance.. idk..
Mnkras replied on at Permalink Reply
Mnkras
C5 really needs duplicate detection, for multiple blocks, if its in edit mode, and versions.

maybe a for each, with a if str == $blah delete it or something idk.

but this is really a core need
andrew replied on at Permalink Reply
andrew
Everybody in this thread might want to check out helpers/html/v2.php in the latest svn of c5. It was a user submitted patch that did a little bit more than yours, Fernandos, but should fix much of those problems. It also handles minification, inline placement, etc... (although I don't know that it's perfect.)

Additionally, @Mnkras: I'm not sure I understand what you mean. The way addHeaderItems() works it should only let you put one copy of a javascript/css file into the header. If it's already there it won't put it twice.
Shotster replied on at Permalink Reply
Shotster
Thanks for rolling this into C5, Andrew. Where's jsmin though? It doesn't seem to be in the location referenced by the new helper class - i.e. libraries/3rdparty.

-Steve
andrew replied on at Permalink Reply
andrew
My fault . It wasn't checked in. Should be resolved.
Fernandos replied on at Permalink Reply
Fernandos
thx for that commit andrew

I'm happy you're enabling the asset-compression feature again :)

Will it aggregate the js files too?
Shotster replied on at Permalink Reply
Shotster
> I've got several blocks that add jQueryUI
> to the header.

Fernandos, maybe I'm not completely understanding the issue, but why don't you just load jQuery UI from your packages using the standard C5 approach, like so...

$hh = Loader::helper('html');
$v->addHeaderItem($hh->javascript('jquery.ui.js'));

It will be loaded only once whether you're logged in or not. Or do you need some functionality that's not in the version that comes with C5?

-Steve
Fernandos replied on at Permalink Reply
Fernandos
Hi, Shotster!
This is just for your information.

We're talking this because there is no way to detect if an item is already in the header or not, if we use different blocks and multiple ones of each on one page. This is not the only problem. Probably you didn't realize that c5 is using a version of jquery ui too and that both collide. ....

btw. it's not my problem to understand howto overcome this issue! I'm just technically interested in a decent solution.

If I replicate the header_required.php and manipulate it to load jQueryUI globally only if(User::isLoggedIn()) it fixes the isse. I could also load it once in the theme.

But as Developer who makes Packages it's interesting to find a solution which works on as many as possible setups.
Shotster replied on at Permalink Reply
Shotster
Fernandos,

I do understand that version 5.4.0 of C5 uses version 1.7.2 of jQuery UI. What I don't understand is why you aren't using it in your blocks. If you include it as I described in my previous post, it will appear only once in the source of the page, regardless of whether you're logged in or not and regardless of how many blocks are used in the page. C5's built-in duplicate suppression takes care of it. I don't understand why you're including another copy of jQuery UI with your blocks. It's already there in C5 waiting to be loaded!

> I'm just technically interested in
> a decent solution.

What I'm saying is that I don't see that there's a problem. Let me state it another way... I've been using jQuery UI also. From my block's view, I simply load the version that comes with C5 (version 1.7.2) just as I described in my previous post. Here it is again...

$hh = Loader::helper('html');
$this->addHeaderItem($hh->javascript('jquery.ui.js'));

The above code loads version 1.7.2 of jQuery UI (the version that comes with C5 version 5.4.0) once and only once, regardless of how many blocks on the page use it and regardless of whether I'm logged in or not.

-Steve
Fernandos replied on at Permalink Reply
Fernandos
hi and thx for posting Steve!

That didn't work for me because I need jQueryUI 1.8 for some plugins.
And it didn't work in general also. Maybe that's related to the filenaming. You're using "jquery.ui.js" so if there is "jquery.ui.js" is in the header but with just a different filename it won't work. The detection is really weak and won't work when you have jqueryui v1.8 required.

(A solution could be replacing the core jquery.ui.js with 1.8 and jquery with 1.4.2 and hope nothing breaks..)

that's related to 5.4's htmlhelper not the svn built.
Shotster replied on at Permalink Reply
Shotster
> That didn't work for me because I need
> jQueryUI 1.8 for some plugins.

Ah ok. I asked that question in a previous post when I said, "Or do you need some functionality that's not in the version that comes with C5?" When you didn't respond to it, I assumed the answer was "no". Sorry about that.

> A solution could be replacing the core
> jquery.ui.js with 1.8 and jquery with
> 1.4.2 and hope nothing breaks..

That's actually what I've done (put the most recent jQuery and jQuery UI in the root js folder to override the core), and I haven't experienced any problems whatsoever. Of course, that's not an option if you're distributing your blocks.

I'm not actually doing anything at the moment that requires the latest jQuery; I just wanted the latest and greatest. Perhaps C5 will include the latest in a maintenance upgrade for 5.4.x. As I said, I haven't experience any issues yet with C5 functionality like the dashboard or anything.

-Steve
Shotster replied on at Permalink Reply
Shotster
Just to clarify for anyone who's following this thread...

My understanding is that there's nothing special or "custom" about the jQuery and jQuery UI files that come with C5. They are simply renamed "jquery.js" and "jquery.ui.js" because they're referenced as such throughout the code.

Therefore, to upgrade to the latest versions, you would simply rename the current releases of jQuery and jQuery UI to 'jquery.js" and "jquery.ui.js" respectively and copy them to the "/js" folder in the root. Additionally, jQuery UI is distributed with a stylesheet, so you should rename that to "jquery.ui.css" and copy it to the "/css" folder in the root. Those files will override the ones in the concrete directory.

-Steve
andrew replied on at Permalink Best Answer Reply
andrew
That is correct.

Our system isn't perfect, of course. As concrete5 sticks around and jQuery UI sticks around, there are going to be more and more versions of both, and more and more addons that require different versions of the jQuery libraries. With that in mind, I do see the utility of some kind of optional labeling system for JavaScript and CSS files - we just want to get the syntax for it right and make sure that it is actually solving real-world problems.
Fernandos replied on at Permalink Reply
Fernandos
^This answered me qestions.

Thank you very very much Andrew! :)
You're great!