Skip to content

Commit afcb79a

Browse files
committed
Merge pull request #15 from bdukes/readme
Add instructions and purpose to README
2 parents 710f446 + ee62a80 commit afcb79a

File tree

2 files changed

+103
-4
lines changed

2 files changed

+103
-4
lines changed
6.66 KB
Binary file not shown.

README.md

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,110 @@
11
DNN JavaScript Libraries
22
===============
33

4-
This repository contains DNN JavaScript Library extensions, wrapping some common
5-
JavaScript libraries for use in DNN.
4+
Version 7.2 of the [DNN Platform](http://www.dnnsoftware.com) introduced the
5+
JavaScript Library extension type. This allows common JavaScript libraries to
6+
exist in a single place within a DNN site, instead of every module, skin, and
7+
piece of content that wants to include them using their own. DNN presently
8+
comes with libraries for jQuery, jQuery UI, jQuery Migrate, Knockout, and
9+
Knockout Mapping.
610

11+
In addition to these built-in libraries, new libraries can be installed into
12+
DNN, and used by various components. DNN allows multiple versions of a
13+
JavaScript library to be used, so one module can request a particular version
14+
of a script, while another requests another. So long as they aren't on the same
15+
page, they will get what they requested; otherwise, DNN will use the higher
16+
version.
17+
18+
19+
Goal
20+
===============
21+
22+
The main benefits in using JavaScript Libraries are realized when they are used
23+
by many separate components within a DNN site (i.e. when there is one common
24+
set of libraries and separate, unrelated DNN skins and modules use those
25+
libraries instead of packaging scripts directly into the extension). In order
26+
to aid in that goal, we are attempting to create a central repository
27+
of common JavaScript Libraries that can be used by many different DNN extension
28+
developers.
29+
30+
Usage
31+
===============
32+
33+
Skins
34+
---------------
35+
Starting in DNN 7.3, there is a skin object called `JavaScriptLibraryInclude`
36+
which can be used to request a JavaScript library (including jQuery, but also
37+
any 3rd party library) from a skin. To do that, you need to register the skin
38+
object at the top of your skin:
39+
40+
<%@ Register TagPrefix="dnn" TagName="JavaScriptLibraryInclude" Src="~/admin/Skins/JavaScriptLibraryInclude.ascx" %>
41+
42+
Then, in the body of the skin, use the skin object to request the library:
43+
44+
<dnn:JavaScriptLibraryInclude runat="server" Name="jQuery" />
45+
<dnn:JavaScriptLibraryInclude runat="server" Name="jQuery-UI" Version="1.10.3" />
46+
<dnn:JavaScriptLibraryInclude runat="server" Name="jQuery-Migrate" Version="1.2.1" SpecificVersion="LatestMajor" />
47+
48+
HTML Skins
49+
---------------
50+
The skin object mentioned above can also be used from HTML skins. It would
51+
look something like this:
52+
53+
<object codetype="dotnetnuke/server" codebase="JavaScriptLibraryInclude">
54+
<param name="Name" value="jQuery" />
55+
<param name="Version" value="1.9.1" />
56+
</object>
57+
58+
Code
59+
---------------
60+
There is also an API to request JavaScript Libraries from code. This is needed
61+
in skins prior to DNN 7.3 and the introduction of the `JavaScriptLibraryInclude`
62+
skin object, as well as from extension code (though extensions can also make use
63+
of the skin object, if desired). The primary entry point for the API is the
64+
`RequestRegistration` method of the `JavaScript` static class in the
65+
`DotNetNuke.Framework.JavaScriptLibraries` namespace. There are three overloads
66+
to `RequestRegistration`:
67+
68+
JavaScript.RequestRegistration(String libraryName)
69+
JavaScript.RequestRegistration(String libraryName, Version version)
70+
JavaScript.RequestRegistration(String libraryName, Version version, SpecificVersion specificity)
71+
72+
The overload which doesn't specify a version will request the latest version of
73+
the library. In order to avoid your extensions breaking unexpectedly, it's
74+
probably best to always specify a version number. The second overload, which
75+
includes the version number will request that specific version of the library.
76+
If that version isn't installed, it will instead display an error. The third
77+
overload is probably the best to use for most scenarios. It allows you to pass
78+
a value indicating how specific the version is, as a value of the
79+
`SpecificVersion` enum. The possible values are `Latest`, `LatestMajor`,
80+
`LatestMinor`, and `Exact`. `Latest` is the behavior of the overload with one
81+
argument, `Exact` is the behavior of the overload with two arguments, while the
82+
other two values allow you to get behavior that is in between strict and loose.
83+
84+
85+
JavaScript Library Features
86+
===============
87+
88+
When requesting that a JavaScript Library is registered, DNN ensures that
89+
both that library's JavaScript file and all of its dependencies' JavaScript
90+
files, get included on the page. The JavaScript library itself will define the
91+
properties that determine how the file is included on the page. Specifically,
92+
the library will indicate its preferred location (from page head, body top, and
93+
body bottom), and can provide a URL to the script on a
94+
<abbr title="Content Distribution Network">CDN</abbr> (along with a JavaScript
95+
expression to use to verify that the CDN loaded the script correctly, so that
96+
DNN can fallback to the local version if the CDN is down). The site
97+
administrator
98+
99+
The other main feature that JavaScript Libraries give you is de-duplication of
100+
scripts. This means that if your module and your skin both request the
101+
[html5shiv library](http://www.dnnsoftware.com/forge/html5shiv), it only gets
102+
included on the page once (rather than both components including their own
103+
version of the script). Likewise, if both components request different versions
104+
of the script, just the higher version will be included.
105+
7106
License
8-
-------
107+
===============
9108

10109
This code is released under the [MIT license](LICENSE.md).
11-
However, the individual libraries are licensed by their respective owners.
110+
However, the individual libraries are licensed by their respective owners.

0 commit comments

Comments
 (0)