aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/comments/frontend/geturl.js
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap/comments/frontend/geturl.js')
-rw-r--r--bootstrap/comments/frontend/geturl.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/bootstrap/comments/frontend/geturl.js b/bootstrap/comments/frontend/geturl.js
new file mode 100644
index 0000000..aa8191b
--- /dev/null
+++ b/bootstrap/comments/frontend/geturl.js
@@ -0,0 +1,35 @@
+// Get either the actual page URL or the declared canonical URL (geturl.js)
+HashOverConstructor.getURL = function (canonical)
+{
+ canonical = (canonical !== false);
+
+ // Get the actual page URL
+ var url = window.location.href.split ('#')[0];
+
+ // Return the actual page URL if told to
+ if (canonical === false) {
+ return url;
+ }
+
+ // Otherwise, return the declared canonical URL if available
+ if (typeof (document.querySelector) === 'function') {
+ var canonical = document.querySelector ('link[rel="canonical"]');
+
+ if (canonical !== null && canonical.href !== undefined) {
+ url = canonical.href;
+ }
+ } else {
+ // Fallback for old web browsers without querySelector
+ var head = document.head || document.getElementsByTagName ('head')[0];
+ var links = head.getElementsByTagName ('link');
+
+ for (var i = 0, il = links.length; i < il; i++) {
+ if (links[i].rel === 'canonical') {
+ url = links[i].href;
+ break;
+ }
+ }
+ }
+
+ return url;
+};