Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAnthon Pang <apang@softwaredevelopment.ca>2013-02-10 17:10:55 +0400
committerAnthon Pang <apang@softwaredevelopment.ca>2013-02-10 17:12:18 +0400
commita5cf854563949b318746f6f7a72fc477b62cb3df (patch)
tree4aa20fc7969278ba68abf415fc3a98634f73721a /js
parent01502d92ebbc8f654828782397062af9451b0e04 (diff)
Refactor JavaScript loader into its own method (loadScript)
Diffstat (limited to 'js')
-rw-r--r--js/README7
-rw-r--r--js/piwik.js55
2 files changed, 37 insertions, 25 deletions
diff --git a/js/README b/js/README
index b811d4a052..102a60a5df 100644
--- a/js/README
+++ b/js/README
@@ -34,7 +34,7 @@ Deployment
http://yuilibrary.com/projects/yuicompressor/ticket/2343811,
or run:
$ cd /path/to/piwik/js/
- $ sed '/<DEBUG>/,/<\/DEBUG>/d' < piwik.js | sed 's/eval/replacedEvilString/' | java -jar yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar --type js --line-break 1000 | sed 's/replacedEvilString/eval/' > piwik-min.js && cp piwik-min.js ../piwik.js
+ $ sed '/<DEBUG>/,/<\/DEBUG>/d' < piwik.js | sed 's/eval/replacedEvilString/' | java -jar yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar --type js --line-break 1000 | sed 's/replacedEvilString/eval/' | sed 's/^[/][*]/\/*!/' > piwik-min.js && cp piwik-min.js ../piwik.js
This will generate the minify /path/to/piwik/js/piwik-min.js and copy it to
/path/to/piwik/piwik.js
@@ -45,3 +45,8 @@ Deployment
Note: if the file "js/tests/enable_sqlite" exists, additional unit tests
(requires the sqlite extension) are enabled.
+* We use /*! to include Piwik's license header in the minified source. Read
+ Stallman's "The JavaScript Trap" for more information.
+
+* We do not include the version number as a security best practice
+ (information disclosure).
diff --git a/js/piwik.js b/js/piwik.js
index fdeccd1efd..7c4298dfe4 100644
--- a/js/piwik.js
+++ b/js/piwik.js
@@ -655,6 +655,31 @@ var
}
/*
+ * Load JavaScript file (asynchronously)
+ */
+ function loadScript(src, onLoad) {
+ var script = documentAlias.createElement('script');
+
+ script.type = 'text/javascript';
+ script.src = src;
+
+ if (script.readyState) {
+ script.onreadystatechange = function () {
+ var state = this.readyState;
+
+ if (state === 'loaded' || state === 'complete') {
+ script.onreadystatechange = null;
+ onLoad();
+ }
+ };
+ } else {
+ script.onload = onLoad;
+ }
+
+ documentAlias.getElementsByTagName('head')[0].appendChild(script);
+ }
+
+ /*
* Get page referrer
*/
function getReferrer() {
@@ -996,30 +1021,12 @@ var
root = root.slice(0, root.length - 9); // remove piwik.php if present
}
- var onLoad = function () {
- Piwik_Overlay_Client.initialize(root, configTrackerSiteId, period, date);
- };
-
- var script = documentAlias.createElement('script');
-
- script.type = 'text/javascript';
-
- if (script.readyState) {
- script.onreadystatechange = function () {
- if (this.readyState === 'loaded' || this.readyState === 'complete') {
- script.onreadystatechange = null;
- onLoad();
- }
- };
- } else {
- script.onload = onLoad;
- }
-
- script.src = root + 'plugins/Overlay/client/client.js?v=1';
-
- var head = documentAlias.getElementsByTagName('head')[0];
-
- head.appendChild(script);
+ loadScript(
+ root + 'plugins/Overlay/client/client.js?v=1',
+ function () {
+ Piwik_Overlay_Client.initialize(root, configTrackerSiteId, period, date);
+ }
+ );
}
/************************************************************