Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.


jQuery & jQuery UI in DNN 6.1.0 and 6.1.1

There have been some exciting changes made with respect to working with JavaScript in DNN 6.1 that give developers more flexibility and everyone faster sites. More importantly, the groundwork has now been laid to build an even better “client side story” for DotNetNuke in future versions.

However, there have been a few bumps on the road while making such significant changes in the framework, and I’d like to make sure everyone is aware of them and provide an opportunity for discussion in the comments.

First, let’s start with the history of jQuery and jQuery UI usage in DNN, and then we’ll talk about where we are now. Please, bear with me as we take a detailed historical journey.

DotNetNuke 5

DotNetNuke 5.0 introduced a new API method to allow for registration of jQuery. This has been the standard way to register jQuery in the core as well as third party modules ever since.

However, some module developers, wanting to still support older versions of DotNetNuke (e.g. 4.x), bypassed the public API and checked the internal flag (HttpContext.Current.Items("jquery_registered")) that denotes whether jQuery has been registered. This wasn’t/isn’t the only technique to support backwards compatibility though, Bruce Chapman has a nice bit of code on his blog that supports the same functionality without sneaking around the public API.

Another important point to note is that when DotNetNuke loads jQuery, it is always loaded in the <head> of the document. This is because jQuery is a framework-level dependency that needs to be loaded prior to any consuming JavaScript, such as script placed in a skin, a page header, registered by a third party module, etc.

DotNetNuke 6

The only real important thing to note is that DotNetNuke 6 introduced jQuery UI into the core framework. At this time, jQuery UI was placed in-between the body and the form.

DotNetNuke 6.1

DotNetNuke 6.1 introduced the new Client Resource Management API. The API allows for specific placement of JS files, using a registration provider. In 6.1, the available options were:

  1. PageHeaderProvider (appended to the head)
  2. DnnBodyProvider (top of the form)
  3. DnnFormBottomProvider (bottom of the form)

jQuery was the only script to use PageHeaderProvider, the rest would use DnnBodyProvider, save for one (a search related script) that would use DnnFormBottomProvider. This was done to try to replicate, as much as possible, what was there previously with respect to order.

Also of important note, the ability to take advantage of the HttpContext key workaround to find out if jQuery was already loaded was removed in DotnetNuke 6.1.0, as the internals of our jQuery registration system changed to use our new Client Resource Management API, and we no longer needed to use this HttpContext key for tracking. The unfortunate side effect of this is that now those modules that were using this technique would load jQuery again. Sometimes this will cause issues, sometimes it will not. It all depends on if anything is extending jQuery in-between the first and second registration. More on that later.

DotNetNuke 6.1.1

The were two specific issues with 6.1.0 that were fixed in DotNetNuke 6.1.1. The first was that the contents of a DotNetNuke Page’s header and Styles skin objects were not being placed in the right order in the page head. This caused issues with ordering when one of these two techniques was being used.

The fix for this issue was to create a new registration provider “DnnPageHeaderProvider” and use this instead of the “regular” PageHeaderProvider, the difference between the two is small but important: The DotNetNuke version inserts the contents at a specific location, whereas the other dynamically appends its contents to the end of the head. Usage of the DotNetNuke version ensures that things are loaded in the expected order.

The second was that jQuery UI was being loaded “too low” in the document. If someone were writing code that depended on jQuery, the possibility existed for them to register their code prior to jQuery being loaded. The decision was to move jQuery UI to the head – to treat it the same way as jQuery. This would improve the overall situation for those that want to take advantage of jQuery UI, by ensuring that it is loaded prior to virtually any consuming code.

The Current Situation

In DotNetNuke 6.1 or 6.1.1, if a module is relying on the internal implementation of the jQuery registration API to avoid loading jQuery more than once, it is not working. jQuery is being loaded twice.

If the second version of jQuery is loaded *after* jQuery UI, which in 6.1.1, it probably is, then jQuery UI will not be available. Here’s why:

  1. jQuery is loaded by the DotNetNuke framework. The jQuery object is defined.
  2. jQuery UI is loaded by the DotNetNuke framework. The jQuery object is extended with jQuery UI specific functionality.
  3. jQuery is loaded again, and the jQuery object is redefined. And, effectively, jQuery UI was “wiped out”.

This may cause the Manage buttons to stop working, as they rely on jQuery UI’s draggable functionality. Also, other module functionality may be broken as well if it depends on jQuery UI.

Next steps/Action Items

The long term answer here is that module developers need to use the public API directly, or use a method such as Bruce Chapman uses that handles using the API without being dependent on a particular version of DNN.

In the short term, if you are locked into a situation where you cannot change the module, and you cannot move back to a previous version of DotNetNuke, the only stop-gap measure that will work is to load jQuery UI again somewhere on the page. This should probably be avoided at all costs, as you will not only have two copies of jQuery on the page, but now two copies of jQuery UI – but if you absolutely have to fix this issue in-place, I would suggest putting a text/html module on the page and placing a jQuery UI script reference in the header or footer. Here is the snippet:

<script type=”text/javascript” src=””http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js”></script>

Summary

Managing JS dependencies is undoubtedly tricky business. I hope that this tour of jQuery & jQuery UI in DotNetNuke history is helpful in understanding the "what?” and the “why?” of the implementation, and how we arrived at seeing these issues in DNN 6.1 and 6.1.1.

Although there have been some significant short term challenges, I believe these challenges will help us, as a whole community, get it right. The average DotNetNuke site contains code from a wide variety of developers. In order to be truly successful, all developers need to settle on a common practice.

Comments

There are currently no comments, be the first to post one.

Comment Form

Only registered users may post comments.

NewsArchives


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Daniels (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (213)
Chris Paterra (55)
Clint Patterson (108)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (181)
Daniel Valadas (48)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (80)
Francisco Perez Andres (17)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (4)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (2)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (40)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Patricio F. Salinas (1)
Patrick Ryan (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott Schlesier (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (4)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (180)
William Severance (5)
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out